(function f () {}).name

R

Ry Nohryb

(function f () {}).name
--> "f"

(function f () {}).bind({}).name
--> ""

Why is this so ?

I can't find anything in the specs about the .name property, where is
it ?

Thanks in advance,
 
S

Sean Kinsey

(function f () {}).name
--> "f"

(function f () {}).bind({}).name
--> ""

Why is this so ?

I can't find anything in the specs about the .name property, where is
it ?

Thanks in advance,

What bind does is to wrap the original function in an anonymous
closure, hence the loss of the name.
As far as I remember .name isn't standardized, and does not exist in
all browsers either (just like calling .toString might reveal the
source code or not)

Sean
 
A

Asen Bozhilov

(function f () {}).name
--> "f"

(function f () {}).bind({}).name
--> ""

Why is this so ?

You can imagine `bind' method as:

Function.prototype.bind = function () {
return function () {
/* Invoke target bounded function */
};
};

So `bind' return *anonymous function* and according MDC documentation
that object has an empty string value for `name' property.
I can't find anything in the specs about the .name property, where is
it ?

The `name' property of function objects is not part of ECMA-262
standard. You can read how it's implemented `name' property in
SpiderMonkey:
<URL: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/name
/>

HTH
 
R

Ry Nohryb



So a bound f() not only has no .name but also can't call itself
*without* depending on an external reference to do so ?

Aha. But I though I've heard them talking a lot about .name in es-
discuss in ~ 2008. I thought it finally made it into es5.

In any case, Sean and Dmitry: KTHNX

P.S.: Why is it that it's taking sooo long to implement ES5 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top