what is log : function() {} in javascript? -
i saw code in quiz , new javascript. although know how function works, still can explain me 3rd line of code. log: function() {} means:
var abc = function() { return { log : function() { console.log(this.val); } }; }
it's object property value function. if do:
var x = abc();
you can do:
x.log()
to call function. here's full example:
var abc = function() { return { log : function() { console.log(this.val); } }; } var x = abc(); x.val = "this value"; var y = abc(); y.val = "this y's value"; x.log(); y.log();
Comments
Post a Comment