Pages
Categories
Archives
JsTweeterManiac
- Seems @WebReflection have too much free time http://bit.ly/beb2tV 3 weeks ago
- looks awesome RT @stshank: Great augmented reality (AR) concept video. How far will we accept brand ads into our lives? http://bit.ly/b7R32U 1 month ago
- Dion names Crockford Crocky :)RT @dalmaer: Crocky keeps on going w/ history & just abt gets 2 JavaScript at the end :) http://bit.ly/cE0trz 1 month ago
- RT @kangax:@infynyxx Actually `Function.prototype.bind` is part of ES5 (now finalized), and is more or less identical to Prototype's `bind`. 1 month ago
- meditating on http://bit.ly/7mKxDI it makes me crazy. I thought i know a lot abt JS inheritance. Need 2 print ECMA specifications n smoke it 1 month ago
- Code Doesn’t Exist Unless It’s Checked In http://bit.ly/4Ah2uI Version control is a part of GTD :) 2 months ago
- RT @kangax: Zakas is doing some extensive research on empty-string URLs behavior — http://bit.ly/5EDWvb What a nice mess we've got there. 2 months ago
- I have now really nice shortname http://bit.ly/djafarov . I think shortnames could be as nice business as domain names:) 2 months ago
- http://bit.ly/6PCND6 nice article about @reply spam on twitter 2 months ago
- Awesome! RT @Evangenieur Google App Engine JavaScript SDK http://www.appenginejs.org/ 2 months ago
-
RSS Links
-
Meta
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"; .... } function bar(){ this.bar="bar"; .... } function observe(child){ //MAGIC childName=child.name||child.toString().match(/function\s*([^\(])\s*\(/)[1]; newConst=function(){ ret={}; child.apply(ret, arguments); observer.push(ret); return ret; }; newConst.name=childName; window[childName]=newConst; } observe(foo); observe(bar); var t1=new foo(); var t2=new bar(); observer // t1,t2