Here is a really lame example of what I am trying to do. This piece of code works.
var Love = {
name: 'Johnny',
kiss: function (girl){
alert(this.name + " kissed " + girl );
}
};
Love.name = "Chris";
Love.kiss("Becky");
I first reassigned the property of name, and then called the method sending my parameter
What I would really like to do, is use JSON to set the “name” property while calling the method. I swear I’ve seen it done somewhere, but I can’t figure it out. So ideally it would look something like this.
Love.kiss({
name: 'Chris'},
"Becky");
Or even something like this.
var Love = {
Guy: 'Johnny',
Girl: 'Mallory',
kiss: function (){
alert(this.Guy + " kissed " + this.girl);
}
};
Love.kiss({
Guy: 'Chris',
Girl; 'Becky'});
Again, I know this is a really stupid example, but the concept has a certain application that I would like to use.
Just run through the keys of the object you pass in as an argument and assign them to
this:See demo