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
Fellow inmates, I don't know if you've heard of [url]http://stackoverflow.com[/url]. It's a question/answer/discussion programmer community, currently in public beta. But it's no expertsexchange.com! It has an elite crowd of users, carrying out fairly interesting technical/philosophical discussions. Oh wait, that reminds me of a familiar forum :) For a bit of code I was working on last night, I ran into a problem which my JS hax0ring skills ran short of solving. I ended up using a different approach, but I'm still pursuing the answer to my initial question. I wanted to give stackoverflow.com a shot first, but unfortunately no one (as of the posting of this thread) has been able to post a satisfactory answer to my question. I think I have a better shot at getting an answer here at OA. Here's [url=http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototypeconstructorapply]the original question[/url] that I posted at stackoverflow.com: -- Let me start with a specific example of what I'm trying to do. I have an array of year, month, day, hour, minute, second and millisecond components in the form [ 2008, 10, 8, 00, 16, 34, 254 ]. I'd like to instantiate a Date object using the following standard constructor: [code] new Date(year, month, date [, hour, minute, second, millisecond ]) [/code] How can I pass my array to this constructor to get a new Date instance? My question actually extends beyond this specific example. I'd like a general solution for built-in JavaScript classes like Date, Array, RegExp, etc. whose constructors are beyond my reach. I'm trying to do something like the following: [code] var comps = [ 2008, 10, 8, 00, 16, 34, 254 ]; var d = Date.prototype.constructor.apply(this, comps); [/code] I probably need a "new" in there somewhere. The above just returns the current time as if I had called "new Date()". I also acknowledge that I may be completely in the wrong direction with the above :) [b]Note:[/b] No eval() and no accessing the array items one by one, please. I'm pretty sure I should be able to use the array as is. [url=http://magnetiq.com/][img]http://magnetiq.com/exports/oa_sig.gif[/img][/url] [small](Edited by [url=http://www.ozoneasylum.com/user/6682]MaGnA[/url] on 10-08-2008 21:21)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »