function f()
{
}
alert (f.prototype); // returns something like [object Object]
My understanding is by default the prototype of custom function should be null or undefined, can someone shed some light? thanks!
prototype, constructor property. Every function has the "prototype" property even if we don't supply it. The default "prototype" is an object with the only property constructor that points back to the function itself. Like this: function Rabbit() {} /* default prototype Rabbit.prototype = { constructor: Rabbit }; */
__proto__ is the actual object that is used in the lookup chain to resolve methods, etc. prototype is the object that is used to build __proto__ when you create an object with new : ( new Foo ).
The __proto__ getter function exposes the value of the internal [[Prototype]] of an object. For objects created using an object literal, this value is Object. prototype . For objects created using array literals, this value is Array.
A function prototype is a definition that is used to perform type checking on function calls when the EGL system code does not have access to the function itself. A function prototype begins with the keyword function, then lists the function name, its parameters (if any), and return value (if any).
The prototype
property of function objects is automatically created, is simply an empty object with the {DontEnum}
and {DontDelete}
property attributes, you can see how function objects are created in the specification:
Pay attention to the steps 9, 10 and 11:
9) Create a new object as would be constructed by the expression new Object()
.
10) Set the constructor property of Result(9) to F. This property is given attributes { DontEnum }
.
11) Set the prototype property of F to Result(9). This property is given attributes as specified in 15.3.5.2.
You can see that this is true by:
function f(){
//...
}
f.hasOwnProperty('prototype'); // true, property exist on f
f.propertyIsEnumerable('prototype'); // false, because the { DontEnum } attribute
delete f.prototype; // false, because the { DontDelete } attribute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With