mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
2.5 KiB
48 lines
2.5 KiB
<h1 id="functionobjects">Function objects</h1>
|
|
|
|
<h2>Property summary</h2>
|
|
|
|
<p>Duktape Function objects add a few properties to standard Ecmascript
|
|
properties. The table below summarizes properties assigned to newly
|
|
created function instances (properties can of course be added or removed
|
|
afterwards):</p>
|
|
|
|
<table>
|
|
<thead>
|
|
<tr><th>Property name</th><th>Compatibility</th><th>Description</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr><td class="propname">length</td><td>standard</td><td>Function argument count (if relevant). Present for all Function objects, including bound functions.</td></tr>
|
|
<tr><td class="propname">prototype</td><td>standard</td><td>Prototype used for new objects when called as a constructor. Present for most constructable Function objects, not copied to bound functions.</td></tr>
|
|
<tr><td class="propname">caller</td><td>standard</td><td>Accessor which throws an error. Present for strict functions and bound functions. Not copied to bound functions.</td></tr>
|
|
<tr><td class="propname">arguments</td><td>standard</td><td>Accessor which throws an error. Present for strict functions and bound functions. Not copied to bound functions.</td></tr>
|
|
<tr><td class="propname">name</td><td>Duktape</td><td>Function name, see below. Copied to bound function from target function.</td></tr>
|
|
<tr><td class="propname">fileName</td><td>Duktape</td><td>Filename or context where function was declared (same name as in error tracebacks). Copied to bound function from target function. </td></tr>
|
|
<tr><td class="propname">callee</td><td>n/a</td><td>Never assigned by default (listed here to clarify relationship to "caller" property).</td></tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<p>User-created Duktape/C functions (<code>duk_push_c_function()</code>) are
|
|
currently missing <code>length</code>, <code>prototype</code>, <code>caller</code>,
|
|
and <code>arguments</code> properties by default. User code can of course
|
|
assign these but is not required to do so. This is intentional as it
|
|
reduces Function object size.</p>
|
|
|
|
<p>The <code>name</code> property is assigned to all functions and is also
|
|
the name used in tracebacks. It is assigned as follows:</p>
|
|
<pre class="ecmascript-code">
|
|
function funcDecl() {
|
|
/* Function declaration: 'name' is declaration name, here 'funcDecl'. */
|
|
}
|
|
|
|
var foo = function namedFunc() {
|
|
/* Named function expression: 'name' is the name used in expression,
|
|
* here 'namedFunc' (not 'foo').
|
|
*/
|
|
}
|
|
|
|
var bar = function () {
|
|
/* Anonymous function expression: 'name' is the empty string. */
|
|
}
|
|
</pre>
|
|
|
|
|