OZONE Asylum
Forums
DHTML/Javascript
Instantiating a JavaScript object by calling prototype.constructor.apply
This page's ID:
30593
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
I've done a few more experiments: I can do this with my own class: [code] function Foo(a, b) { this.a = a; this.b = b; this.toString = function () { return this.a + this.b; }; } var foo = new Foo(1, 2); Foo.prototype.constructor.apply(foo, [4, 8]); document.write(foo); // Returns 12 -- yay! [/code] But it doesn't work with the intrinsic Date class: [code] var d = new Date(); Date.prototype.constructor.call(d, 1000); document.write(d); // Still returns current time :( [/code] Neither does it work with Number: [code] var n = new Number(42); Number.prototype.constructor.call(n, 666); document.write(n); // Returns 42 [/code] Maybe this just isn't possible with intrinsic objects? I'm testing with Firefox BTW. [url=http://magnetiq.com/][img]http://magnetiq.com/exports/oa_sig.gif[/img][/url]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »