Douglas Crockford wrote in his book (Page 4):
Throughout the book, a method
method is used to define new methods, This is its definition:
All native functions in JavaScript inherit from Function.prototype
. Number
, String
, Object
, Array
and RegExp
are all functions, therefore they inherit from Function.prototype
.
method
is intended to be called on constructor functions. Its job is to make the function you supply to it into a method that exists for every object created by the constructor function on which you called method
. You will notice that in the functions that Crockford passes to method
, he makes use of this
, which is a reference to the object on which the method was called. Array.dim
, Array.matrix
and Array.identity
make no use of this
because they operate independently of any particular array and hence do not need to be methods of individual array objects. They are assigned as properties of the Array
function for convenience: they could equally well exist on their own as functions in the global scope.