I happened to chance by the following javascript code and it works beautifully.
var Mario = {
name: 'Mario',
sayHello: function(name) {
return 'Hi I\'m ' + this.name;
}
};
var Luigi = {
name: 'xoxox'
};
alert(Mario.sayHello.call(Luigi , name));
However, when i change the property 'name' to something else (say 'xyz'), like so :
var Mario = {
xyz: 'Mario',
sayHello: function(xyz) {
return 'Hi I\'m ' + this.xyz;
}
};
var Luigi = {
xyz: 'xoxox'
};
alert(Mario.sayHello.call(Luigi , xyz));
It doesn't work!!
What does this behaviour signify and why isn't it working? Can someone explain?
name?namein window