Javascript named function assigned to a property -
i'm working on javascript code defines class methods defining prototype object, shown below:
/** * @constructor */ function myclass() { var somefield = 'hello world'; } myclass.prototype = { getsomefield1: function getsomefield2() { return somefield; } };
i have 2 questions:
what
getsomefield2
, , accessible code?can give examples of scenario might advantageous use different names key , function name? have thought confuse people reading code.
in other instances of similar code, either property , function names match, or function unnamed.
the main benefit browsers show names of functions in stack traces.
typically, people use anonymous function when assigning property or variable. chrome had been pretty @ figuring out should use property or variable name on stack trace, ie used show anonymous.
also named functions have name
property
(function a(){}).name // (function(){}).name // ""
Comments
Post a Comment