lundi 26 mai 2014

passing javascript parameters from an object constructor to the object's method?


Vote count:

0




Is it possible, while setting up a constructor, to have it's parameters passed right into one of it's methods? Here's what i mean:



function jedi(name,text){
this.name = name;
this.quote = function quote(name,text){
return name + " said " + text;
};
}

var obiwan = new jedi('Obi-Wan','Fear leads to the darkside');
console.log(obiwan.quote()); //renders as undefined said undefined

//this works fine though
console.log(obiwan.quote('Obi-Wan','Fear leads to the darkside'));


Is it possible to pass the 'name' and 'text' parameters right from 'var obiwan = new jedi()' to 'obiwan.quote()'? I hope my question makes sense. Thanks in advance to anyone that can help me out!



asked 8 secs ago






Aucun commentaire:

Enregistrer un commentaire