Hi, all!
Today i figured out that i could extend my class binding framework
with 6 lines of code to allow JS-side classes to extend native bound
classes (i only had to change how the native "this" object is searched
for, recursively checking the prototype object).
i've *almost* got this working, but i'm having a problem understanding
some JS behaviour.
For this example, assume MyNative is a C++ type bound to JS, and it
has a native function, hi(), which is bound to JS. The following
*almost* does what i want, and i'll explain afterwards why it's wrong,
and will ask for help on understanding why my preferred approach isn't
working:
function SubType()
{
return this;
}
SubType.prototype = new MyNative();
var sub = new SubType();
print(sub.hi()); // prints "hi!"
That works, but the prototype of all SubType objects is a single,
shared object, which is obviously going to cause me grief if i'm
subclassing a Window type (all instances would share the same native
window!).
What i'd LIKE to do is:
function SubType()
{
this.prototype = new MyNative();
return this;
}
var sub = new SubType();
print(sub.hi());
But for some reason that's then failing with:
TypeError: Object #<a SubType> has no method 'hi'
Why does the former variant of setting the prototype work, but the
latter does not? How can i achieve the effect i'm looking for? Keep in
mind that the constructor for a given native type might require
certain arguments which only the client can provide, so i cannot
generically provide some default instance of such a type.
:-?
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---