Named Function Properties of an Object

render: function render(context, partials) {
  return this.r(context, partials);
},

Given this code from the new hogan.js Twitter library to demonstrate this problem; what is the purpose of naming a function twice?

+5
source share
3 answers

If it were necessary, the function rendercould call itself throughrender() , but is render()not available elsewhere .

In addition, in the stack trace, you will see renderas the name of the function, not anonymous function.

+7
source

This is necessary for a recursive call.

0
source

- , ,

object.render(context, partials);

. .

, , .

var render = function render(n) {
    console.log("render");
    if (n < 1)
      render(n + 1);
};
render(0);

Edit: Sorry, I wrote something really wrong in the first revision.

0
source

All Articles