I am having a little trouble understanding why Result is false in the following code.
Other objects in the library that are required to have a size will check if the size parameter is an instance of InterfaceKit.Core.Size. Currently, instanceof is returning false.
var InterfaceKit = {
Core : {
Size: function( i_Width, i_Height ){
Object.defineProperties(this, {
m_Width : {
value: Number( i_Width ) ? Number( i_Width ) : 0
, writable: true
}
, m_Height : {
value: Number( i_Height ) ? Number( i_Height ) : 0
, writable: true
}
});
this.__proto__ = {
SetWidth: function( i_Width ){
if( Number( i_Width ) )
this.m_Width = Number( i_Width );
}
, GetWidth: function(){
return this.m_Width;
}
, SetHeight: function( i_Height ){
if( Number( i_Height ) )
this.m_Height = Number( i_Height );
}
, GetHeight: function(){
return this.m_Height;
}
};
this.__proto__.constructor = InterfaceKit.Core.Size;
}
}
};
var Result = (new InterfaceKit.Core.Size( 10, 10 ) instanceof InterfaceKit.Core.Size); //false
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/instanceof
In other words…
Therefore the constructor’s prototype is not in the prototype chain of the object. Which means it is not an
instanceofthe constructor, even if that constructor did “construct” that object.But really, just don’t use
__proto__.