1

I want to chain methods in Javascript (using Node.js).

However, I encountered this error:

var User = {
    'deletes': function() {
        console.log('deletes');
        return this;
    },
    'file': function(filename) {
        console.log('files');
    }
};

User.deletes.file();


node.js:50
    throw e; // process.nextTick error, or 'error' event on first tick
    ^
TypeError: Object function () {
        console.log('deletes');
        return User;
    } has no method 'file'
    at Object.<anonymous> (/tests/isolation.js:11:14)
    at Module._compile (node.js:348:23)
    at Object..js (node.js:356:12)
    at Module.load (node.js:279:25)
    at Array.<anonymous> (node.js:370:24)
    at EventEmitter._tickCallback (node.js:42:22)
    at node.js:616:9

How could I make it work?

2 Answers 2

4

You are not invoking the deletes function (the string representation of the function is what is printed in the error trace).

Try:

User.deletes().file()

Happy coding.

Sign up to request clarification or add additional context in comments.

Comments

1

One thing is missing: User.deletes().file(<filename>). I'm not sure, maybe this raise an error?

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.