[英]In Javascript, is Array.join really Array.prototype.join?
I wonder why even in the Javascript Definitive Guide 6th ed, O'Reilly, p. 我想知道为什么即使在Javascript权威指南第6版,O'Reilly, p。 149 - 150 , it keeps on using
Array.join()
or Array.concat()
. 149-150 ,它继续使用
Array.join()
或Array.concat()
。 Should it be Array.prototype.join()
instead? 它应该是
Array.prototype.join()
吗?
But while Chrome doesn't have Array.join
defined, Firefox actually does, and it can be invoked by Array.join(array, string)
. 但是虽然Chrome没有定义
Array.join
,但Firefox确实可以,并且可以通过Array.join(array, string)
调用它。 The difference might be important as one is a class method and the other is an instance method. 差异可能很重要,因为一个是类方法,另一个是实例方法。 I wonder why that is?
我不知道这是为什么?
The book kept on using Array.join
even in the Core Javascript Reference docs, but maybe it meant Array.prototype.join
, and also, it seems to suggest that Array
has a length
property, but it really should also be a property of Array.prototype
, and is Array.prototype.length
? 即使在Core Javascript Reference文档中,本书也继续使用
Array.join
,但也许它意味着Array.prototype.join
,而且,它似乎暗示Array
有一个length
属性,但它确实也应该是Array.prototype
的属性Array.prototype
,是Array.prototype.length
?
By the way, it seems that Firefox's implementation of Array.prototype.join
can be 顺便说一句,似乎Firefox的
Array.prototype.join
的实现可以
Array.prototype.join = function(s) {
return Array.join(this, s);
}
but I don't see that usually being done (defining a class method that can be invoked on an instance). 但我没有看到通常这样做(定义一个可以在实例上调用的类方法)。
FireFox puts a version of prototyped methods on the related constructor. FireFox在相关构造函数上放置了原型方法的一个版本 。
This isn't part of the ECMAScript standard, but rather is part of the specific JavaScript superset of ECMAScript. 这不是ECMAScript标准的一部分,而是ECMAScript的特定JavaScript超集的一部分。
The book should make that distinction, unless the book is talking specifically about the JavaScript extensions. 除非本书专门讨论JavaScript扩展,否则本书应该有所区别。
Keep in mind that JavaScript !== ECMAScript. 请记住JavaScript!== ECMAScript。 ECMAScript is the language standard, and JavaScript is an implementation of the 3rd edition of that standard, and includes a superset of functionality not specified by the standard.
ECMAScript是语言标准,JavaScript是该标准第3版的实现,包括标准未指定的功能超集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.