Pages
Categories
Archives
Monthly Archives: August 2009
take control over class constructor
Javascript doesn’t give us simple way to control object constructing. We have new operator, but we cannot control it. Unless we do some magic.
Lets assume we have an observer instance, few classes and we want every instance of this classes to be ‘observed’.
var observer=[]// simplest ever
function foo(){
this.foo="foo";
[...]
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 [...]
“Even Faster Websites”