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:

  1. what getsomefield2, , accessible code?

  2. 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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -