For the code below, I provide isShiny
for an object obj
, it is listed as part of the attribute, which is essentially a key-value pair,
where the key is isShiny
,
value is the anonymous function.
But when I provide isShiny
for a function func
, what really happened behind the scene? When I print out a function, there is no hint of where the isShiny
is.
var obj ={} //this is an object
obj.isShiny = function () {
console.log(this);
return "you bet1";
};
console.log(obj);
var func = function () {console.log(this)}; //this is a function
func.isShiny = function () {
console.log(this);
return "you bet1";
};
console.log(func);
This is the output for console.log
from browser.