function Train(){
this.name = "Choo Choo";
this.show = function(){
return this.name;
};
};
var engine = new Train;
engine.name = "Orient Express";
function go(){
alert(engine["show"].call(engine));
}
What is cool is that you can access a function just like any other property of the object. So the go function could take a parameter that would be the name of the function to call on the engine object. It's like reflection, only better.
No comments:
Post a Comment