Reputation: 151036
I wonder why even in the Javascript Definitive Guide 6th ed, O'Reilly, p. 149 - 150, it keeps on using Array.join()
or Array.concat()
. Should it be Array.prototype.join()
instead?
But while Chrome doesn't have Array.join
defined, Firefox actually does, and it can be invoked by 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
?
By the way, it seems that Firefox's implementation of Array.prototype.join
can be
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).
Upvotes: 3
Views: 586
Reputation: 48761
FireFox puts a version of prototyped methods on the related constructor.
This isn't part of the ECMAScript standard, but rather is part of the specific JavaScript superset of ECMAScript.
The book should make that distinction, unless the book is talking specifically about the JavaScript extensions.
Keep in mind that 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.
Upvotes: 1