Pages
Categories
Archives
JsTweeterManiac
- #nodejs google plus fan page just crossed 1000 followers! http://t.co/IdbGqaXd 4 days ago
- #nodejs google plus fan page just crossed 800 followers http://t.co/IdbGqaXd ! 2 weeks ago
- hey @ryah {http://t.co/fdc8SCPR} you've done some cool stuff, I'm a fan via {http://t.co/2NPs9fNA} 2 weeks ago
- node.js makes programming fun again https://t.co/qgZwpOzL 3 weeks ago
- core #nodejs in #coffeescript? How about debugging this? http://t.co/iICMV30r 1 month ago
- 1999:Java - is for small projects,use C. 2005:Ruby - is for small projects,use Java. 2011:node.js - is for small projects, use Ruby for big 1 month ago
- >npm xmas 1 month ago
- WebStorm 3 officially out. With #nodejs and #coffeescriptsupport http://t.co/kCrF8Ba4 1 month ago
- Behold of #eval fanpage join #javascript #evil legions! https://t.co/9b2NotMs 1 month ago
- Position: fixed revisited http://t.co/jJ0fPsoy 1 month ago
-
RSS Links
-
Meta
javascript constructor with arguments
There was an interesting question on stackoverflow recently. Nobody had right answer. Now after few days i got it! It is really a peace of JS art.
The question was if it is possible to call constructor like this:
someClass(arg1,arg2,...,argN){ .... //implementation }having just an Array of arguments [arg1,arg2,...,argN]. First thought was just to use apply. Next was: how can you use apply on a constructor? But it seems you really can:)
var args=[arg1,arg2,...,argN]; var inst={};// this will be instance of our class someClass.apply(inst,args);// magic hereYou see from this point of view javascript constructor is just a method(function) applied to object cloned from its prototype.