Possible Duplicate:
Javascript syntax I haven't seen till now, what does it do really?
I was checking out a library called def.js which makes JavaScript objects inherit in a similar fashion as Ruby. But the thing that I couldn't really get was the way JavaScript was used in the example provided:
def ("Person") ({
init: function(name){
this.name = name;
},
speak: function(text){
alert(text || "Hi, my name is " + this.name);
}
});
def ("Ninja") << Person ({
init: function(name){
this._super();
},
kick: function(){
this.speak("I kick u!");
}
});
var ninjy = new Ninja("JDD");
ninjy.speak();
ninjy.kick();
in short, the two points are:
- def ("Person")({}); // parentheses after function call
- def ("Ninja") << Person ({}); // two function calls seperated by the operator <<
Is this a correct/legal use of JavaScript, and if it is, what's it's meaning i.e. how is interpreted by the browser.