Core Primitive In JavaScript Function Invocation
by spring1975
HTML
<div id="output1"></div>
JavaScript
//http://www.codeproject.com/Articles/824517/Is-JavaScript-function-invocation-is-confusing
function fnGreet(thing) {
$('#output1').append($('<div>').text(this + " says hello " + thing));
}
fnGreet.call("Maddy", "world");
fnGreet('Maddy');
var person = {
name:'Maddy',
greet: function (thing) {
console.log(this + " says hello " + thing);
}
};
// this:
person.greet("world"); // Output - [object Object] says hello world
// takes it to this:
person.greet.call(person, "world"); // Output- [object Object] says hello world