1

As told in the Douglas JavaScript good parts, I tried to create a array method as below,

Array.method('reduce', function (f, value) {

});

but I am getting

Uncaught TypeError: Array.method is not a function at :1:7

2 Answers 2

1

There is no method() in the Array. In Douglas Crockford's posts, he have created that method himself and then uses it.

This is the code

Object.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
};
Sign up to request clarification or add additional context in comments.

Comments

1

You need to read the section titled "A Simple Testing Ground" on page 20:

Throughout the book, a method method is used to define new methods. This is its definition:

Function.prototype.method = function (name, func) {
  this.prototype[name] = func;
  return this;
};

It will be explained in Chapter 4.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.