参数如何成为Array.slice的合法参数? [英] How are arguments a legit argument to Array.slice?

查看:65
本文介绍了参数如何成为Array.slice的合法参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码示例中,参数如何成为Array.slice的合法

参数?

Function.prototype.bind = function(){

var fn = this,args = Array.prototype.slice.call(arguments),object =

args.shift();

return function() {

返回fn.apply(对象,

args.concat(Array.prototype.slice.call(arguments)));

} ;

};

var myObject = {};

函数myFunction(){

返回此== myObject;

}


myFunction.bind(myObject)();

In the code sample below, how are arguments a legitimate
argument to Array.slice?
Function.prototype.bind = function(){
var fn = this, args = Array.prototype.slice.call(arguments), object =
args.shift();
return function(){
return fn.apply(object,
args.concat(Array.prototype.slice.call(arguments)) );
};
};
var myObject = {};
function myFunction(){
return this == myObject;
}

myFunction.bind(myObject)();

推荐答案

lorlarz写了
lorlarz wrote

在下面的代码示例中,参数如何成为Array.slice的合法

参数?


Function.prototype.bind = function(){

var fn = this,args = Array.prototype.slice.call(arguments),

object = args.shift();

返回函数(){

返回fn.apply (对象,

args.concat(Array.prototype.slice.call(arguments)));

};

};

var myObject = {};

函数myFunction(){

返回此== myObject;

}


myFunction.bind(myObject)();
In the code sample below, how are arguments a legitimate
argument to Array.slice?

Function.prototype.bind = function(){
var fn = this, args = Array.prototype.slice.call(arguments),
object = args.shift();
return function(){
return fn.apply(object,
args.concat(Array.prototype.slice.call(arguments)) );
};
};
var myObject = {};
function myFunction(){
return this == myObject;
}

myFunction.bind(myObject)();



拟由人类阅读的代码(因此任何发布到Usenet的代码

,目的是让其他参与者检查一个

组)应该缩进(在帖子中使用空格而不是标签,因为标签不要

在新闻阅读器中接收统一(或必然有用)处理

软件)。


在上面的代码中 - arguments - 永远不是Array.slice的参数。所有

出现的 - 参数 - 作为参数作为参数 -

Function.prototype.call - 。


理查德。

Code that is intended to be read by humans (so anything posted to Usenet
with the intention of its being examined by other participants in a
group) should be indented (using spaces in posts not tabs as tabs don''t
receive uniform (or necessarily useful) handling in newsreader
software).

In the code above - arguments - is never an argument to Array.slice. All
occurrences of - arguments - as an argument are as an argument to -
Function.prototype.call -.

Richard.


8月29日,6:36 * am,lorlarz< lorl ... @ gmail.comwrote:
On Aug 29, 6:36*am, lorlarz <lorl...@gmail.comwrote:

在下面的代码示例中,参数如何成为Array.slice的合法

*参数?


Function.prototype .bind = function(){

var fn = this,args = Array.prototype.slice.call(arguments),object =

args.shift();

返回函数(){

返回fn.apply(对象,

args.concat(Array.prototype.slice.call(arguments)) );};
In the code sample below, how are arguments a legitimate
*argument to Array.slice?

Function.prototype.bind = function(){
var fn = this, args = Array.prototype.slice.call(arguments), object =
args.shift();
return function(){
return fn.apply(object,
args.concat(Array.prototype.slice.call(arguments)) );};



在我看来:


返回fn.apply(object,args);


就够了。

-

Rob

Seems to me that:

return fn.apply(object, args);

is sufficient.
--
Rob


8月28日, 6:16 * pm,Richard Cornford < Rich ... @ litotes.demon.co.uk>

写道:
On Aug 28, 6:16*pm, "Richard Cornford" <Rich...@litotes.demon.co.uk>
wrote:

lorlarz写道


在下面的代码示例中,参数如何成为Array.slice的合法

参数?
In the code sample below, how are arguments a legitimate
argument to Array.slice?


Function.prototype.bind = function(){

var fn = this,args = Array.prototype.slice .call(arguments),

object = args.shift();

return function(){

return fn.apply(object,

args.concat(Array.prototype.slice.call(arguments)));

};

};

var myObject = {};

函数myFunction(){

返回此== myObject;

}
Function.prototype.bind = function(){
var fn = this, args = Array.prototype.slice.call(arguments),
object = args.shift();
return function(){
return fn.apply(object,
args.concat(Array.prototype.slice.call(arguments)) );
};
};
var myObject = {};
function myFunction(){
return this == myObject;
}


myFunction.bind(myObject)();
myFunction.bind(myObject)();



拟由人类阅读的代码(所以发布到Usenet的任何内容

,目的是让其他参与者查看一个

组)应该缩进(在帖子中使用空格而不是标签,因为标签不要

在新闻阅读器中接收统一(或必然有用)处理

软件)。


在上面的代码中 - arguments - 永远不是Array.slice的参数。所有

出现的 - 参数 - 作为参数作为参数 -

Function.prototype.call - 。


Richard.-隐藏引用文字 -


- 显示引用文字 -


Code that is intended to be read by humans (so anything posted to Usenet
with the intention of its being examined by other participants in a
group) should be indented (using spaces in posts not tabs as tabs don''t
receive uniform (or necessarily useful) handling in newsreader
software).

In the code above - arguments - is never an argument to Array.slice. All
occurrences of - arguments - as an argument are as an argument to -
Function.prototype.call -.

Richard.- Hide quoted text -

- Show quoted text -



此代码来自新JavaScript的草稿一本专家预定

。他正在抓取

函数的arguments属性并传递

它作为Array.prototype.slice的参数


函数

接收的arguments属性的内容只是对象myObject,所以似乎没有什么可以切片。


我可能要问作者本人;也许这个

是草案中的代码错误。

This code is from a draft of a new JavaScript book
by a major expert. He is grabbing
the arguments property of the function and passing
it as an argument to Array.prototype.slice

The contents of the arguments property that the function
receives is just the object myObject, so there seems to be
nothing to slice.

I may have to ask the author himself; perhaps this
is a code error in the draft.


这篇关于参数如何成为Array.slice的合法参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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