0

For example using Underscore library, the following code works:

var myobject = {};
_.extend(myobject, { 
  method: 'demo'
});

Here, myobject.method prints demo. But the following example does not work, myboject.method is undefined, when I set the value of method to be a function instead of a string:

var myobject = {};
_.extend(myobject, { 
  method: function() {
    return 'demo'
  });
});
1
  • 2
    Syntax is not right... Commented Nov 6, 2013 at 6:18

1 Answer 1

1

Remove the extra );

var myobject = {};
_.extend(myobject, { 
  method: function() {
    return 'demo'
  } // ); <-- remove this
});
Sign up to request clarification or add additional context in comments.

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.