3 ms·
"To create a new member function, create a new anonymous function and assign it to the prototype property of the object. " I prefer not to use anonymous functi
by solutionyogi 16y ago
"To create a new member function, create a new anonymous function and assign it to the prototype property of the object. "
I prefer not to use anonymous function. I will use named function so that my stack trace is comprehensible when I am debugging.
myObject.prototype.memberMethod = function()
{
// code to execute within this method
}
becomes
myObject.prototype.memberMethod = function memberMethod()
{
// code to execute within this method
}
Also, what's up with naming the constructor function as 'myObject'. JS prototypical nature is confusing as is and using an example like this can only make it harder to understand.
- mnemonik 16y agoIndeed, however you have to be careful about the outer scope that the assignment is happening in (because of IE): http://kangax.github.com/nfe/#jscript-bugs http://kangax.github.com/nfe/#jscript-bugs The other option, if you are on Webkit, is to assign something to the `displayName` property of a function or method. This is explained really well here: http://www.alertdebugging.com/2009/04/29/building-a-better-javascript-profiler-with-webkit/ http://www.alertdebugging.com/2009/04/29/building-a-better-j...
- solutionyogi 16y agoYeah, I should have added the warning about JScript bugs. At least the first two bugs listed on that page has been fixed in IE9.
- mnemonik 16y agoDo you have a link regarding IE9 fixing the NFE bugs? Googling "ie9 named function expression" didn't yield particularly good results. Thanks.