I have always used to write function prototype declaration in this way:
var O = function () {};
O.prototype.fn = function () {}
But Some developer write in this way:
var O = function () {};
O.prototype.fn = function fn () {}
Are these way equivalent? If not, what is the advantage for using the second way?
var O = function () {};
O.prototype.fn = function fn () {}
var a = function _a() { }vs
var a = function () { }The former is called a named function expression,
The latter is just a function assignment.
A NFE has two advantages
A NFE has disadvantages. Kangax talks about them in depth.
Personally I use NFE everywhere and ignore the memory leaks IE makes. However since IE leaks these function names into global scope, an effort should be made to make them unique.
Because IE has a habit of leaking these names into global scope, I try to make them unique.
This is why I prepend function declaration names with
_As a side-note there’s an alternative pattern to
Which is