(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,
--
Jorge.
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
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
On Sep 1, 2:02 pm, Asen Bozhilov <asen.bozhi...@gmail.com> wrote:
> (...)
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 ?
--
Jorge
A bout function just presets a ThisBinging (that is [[BoundThis]]) and
partial arguments (that are [[BoundArgs]]). Moreover, [[BoundThis]]
isn't used in case of `new'.
The [[Code]] then is used of the *original* function. The bound function
just /delegates/ to it.
// BESEN r.110
var f = (function foo(bar) {
print(
this.x,
arguments.callee === f,
arguments.callee === foo
);
if (bar) {
return;
}
arguments.callee(true);
}).bind({x: 10});
f();
I wrote recently a detailed description of bound function of ES5. If
interested, take a look:
http://dmitrysoshnikov.com/notes/note-1-ecmascript-bound-functions/
> 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 ?
In big companies decision-making process is not so fast. As a
consequence, an implementation process is also slows down. At the same
time, the one individual person (e.g. Benjamin Rosseaux aka BeRo) may
implement it much faster -- because there is no need to discuss it in
many (often not so useful, and even useless) talks, wasting the time.
From this viewpoint, BeRo's work is just great. And it regards also to
quick fixing of bugs. We just find them, contact to BeRo, and they are
already fixed today/tomorrow. Such process of course impossible in big
companies when people go to work "to write JavaScript".
Dmitry.
> --
> Jorge
>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)
ISO/IEC 16262 includes :
15.3.4.2 Function.prototype.toString ( )
An implementation-dependent representation of the function is returned.
This representation has the syntax of a FunctionDeclaration. Note in
particular that the use and placement of white space, line terminators,
and semicolons within the representation string is implementation-
dependent.
Revealing a version of the source code is REQUIRED. Some browsers do it
/verbatim/; some seem to expand a tokenised form.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)