arguments.callee.name与functionName.name? [英] arguments.callee.name vs. functionName.name?

查看:71
本文介绍了arguments.callee.name与functionName.name?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

worldName.name在世界上有什么用?那就是:


函数functionName(){return functionName.name; }


我的意思是,我已经写出了函数的名字,所以看起来它不是很有用或者有效率。 />

对我来说,this.name似乎最合适,但当然除非定义为类,否则在函数的

上下文中不起作用,当然这当然是然后名称属性

不适用于调用函数。


当然,你总是可以自己分配它:

function functionName(){this.name = arguments.callee.name; }


但无论如何......我原来的问题是,使用functionName.name作为

与arguments.callee.name相对的目的是什么? (第二个是有用的,高效的和动态的。)


谢谢。


-Lost

What in the world is functionName.name good for? That is:

function functionName() { return functionName.name; }

I mean, I already had to write out the function''s name so it seems that it is not very
useful or efficient.

To me, this.name seems most appropriate, but of course that does not work within the
context of a function unless defined as a class, which of course then the name property
does not apply to the calling function.

Of course, you could always assign it yourself like:

function functionName() { this.name = arguments.callee.name; }

But anyway... my original question, what is the purpose of using functionName.name as
opposed to arguments.callee.name? (The second being useful, efficient and dynamic.)

Thanks.

-Lost

推荐答案

functionName.name在世界上有什么用?


鉴于85%-95%的可能用户不支持它好的

什么都不做 - 如果我们谈的是原生的名字属性

函数对象。这个属性是Gecko的专有扩展。


类似的功能可以模拟交叉UA虽然使用

toString /解析如果toString没有被覆盖。因此,如果理论上将

视为如果可用,这将是有用的财产吗?然后是 - 有时候;

说序列化。

What in the world is functionName.name good for?

Given that it is not supported on 85%-95% of possible users it is good
for nothing - if we are talking of the native "name" property in
function object. This property is a proprietary extension in Gecko.

Similar functionality can be emulated cross-UAs though by using
toString/parsing if toString is not overriden. So if put theoretically
as "would be such property useful if available?" then yes - sometimes;
say for serializations.


" VK" < sc ********** @ yahoo.comwrote in message

news:11 ******************** **@v45g2000cwv.googlegr oups.com ...
"VK" <sc**********@yahoo.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...

> functionName.name在世界上有什么用?
>What in the world is functionName.name good for?



鉴于85%-95%的可能用户不支持它是好的

什么都不做 - 如果我们谈论的话本地名称属性

函数对象。此属性是Gecko的专有扩展。


Given that it is not supported on 85%-95% of possible users it is good
for nothing - if we are talking of the native "name" property in
function object. This property is a proprietary extension in Gecko.



哎呀,我想我错过了那一部分。我非常渴望找到一种方法来获取*只是*

函数名称而不是arguments.callee返回的整个负载。


我发现了尝试通过子字符串阻止一些数据是行不通的。

当我在Core JS 1.5参考中遇到它时,我认为这将是明确的

解决方案。

Oops, I guess I missed that part. I was desperate to find a way to get *just* the
function name instead of the entire load that arguments.callee returns.

I found out that attempting to snag some of the data via substring was not going to work.
When I ran across that in the Core JS 1.5 reference I thought it would be the definitive
solution.


类似的功能可以通过使用

toString / parsing来模拟cross-UAs,如果toString没有被覆盖。因此,如果理论上将

视为如果可用,这将是有用的财产吗?然后是 - 有时候;

说序列化。
Similar functionality can be emulated cross-UAs though by using
toString/parsing if toString is not overriden. So if put theoretically
as "would be such property useful if available?" then yes - sometimes;
say for serializations.



什么是UA?


-Lost

What is a "UA"?

-Lost


VK写道:



VK wrote:

Hi,

>世界上有什么functionName.name有用吗?
>What in the world is functionName.name good for?



鉴于85%-95%的可能用户不支持它是好的

什么都不做 - 如果我们谈论的话本地名称属性

函数对象。此属性是Gecko的专有扩展。


Given that it is not supported on 85%-95% of possible users it is good
for nothing - if we are talking of the native "name" property in
function object. This property is a proprietary extension in Gecko.



同意跨浏览器参数,但是'function.name''

可供其他用户代理使用,会得出结论仍然存在:它本质上是(现代)javascript中的无用功能。


在概念化功能时,应该考虑到它们是

自然匿名对象,可以绑定到任何对象的零或多个命名的

属性。换句话说,函数可以是匿名的

(甚至不在某个命名属性上声明),或者有几个名称。


操纵方法函数名称通常表示

程序员不知道函数是一等对象

在javascript中;他/她的脚本编写方法不完整,通常会导致一些复杂和不自然的生产。


< URL:http://en.wikipedia.org / wiki / First-class_object>

< URL:http://en.wikipedia.org/wiki/First-class_function>

Agreed for the cross-browser argument, however were ''function.name''
available to other user agents, would the conclusion still remain : it
is, by essence, a useless feature in (modern) javascript.

When conceptualizing functions, one should consider that they are by
nature anonymous objects, which can be bound to zero or many named
properties of any object. In other words, functions can be anonymous
(not even declared on some named property), or have several "names".

The approach of manipulating functions by their name generally indicates
that the programmer is not aware that functions are first-class objects
in javascript; his/her scripting approach is incomplete and generally
results in some complicated and unnatural production.

<URL:http://en.wikipedia.org/wiki/First-class_object>
<URL:http://en.wikipedia.org/wiki/First-class_function>


类似的功能可以模拟交叉UA虽然使用

toString /解析如果toString没有被覆盖。
Similar functionality can be emulated cross-UAs though by using
toString/parsing if toString is not overriden.



function funcName(func){

var p = / function\s +(\ w +)/。exec(func +" ;");

返回p?p [1]:null;

}


....是代码Gosha Bine在他晚期的func.js中提出

function funcName(func){
var p=/function\s+(\w+)/.exec(func+"");
return p?p[1]:null;
}

.... was the code Gosha Bine proposed in his late func.js.


因此,如果理论上将

作为如果可用的话,这样的属性会有用吗? "然后是 - 有时候;

说序列化。
So if put theoretically
as "would be such property useful if available?" then yes - sometimes;
say for serializations.



序列化是将一些实时对象转换为某些字节或文本的过程,以便将某些实时对象转换为某些字节或文本,以便它可以保存

和/或安全传输到其他程序。膨胀序列化的

代码然后允许恢复执行。


在javascript中,函数名称不会用于某些序列化

进程,因为不仅名称与函数'

对象标识无关,而且与函数对象本身无关

(名称)与它所属的对象相关的命名属性。

问候,

Elegie。

Serialization is the process by which you transform some ''live'' object
or execution context into some bytes or text, so that it can be saved
and/or safely transmitted to other programs. Inflating the serialized
code then permits to resume the execution.

In javascript, functions names would not be used in some serialization
process, because not only has the name nothing to do with the function''s
object identity, but also nothing to do with the function object itself
(the name related to the object to which it belongs as a named property).
Regards,
Elegie.


这篇关于arguments.callee.name与functionName.name?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆