If I call myRobot.Speak.sayHi() it always returns undefined. Please, what am I doing wrong? Thanks for reply!
var Factory = (function() {
// Constructor
var Robot = function() {
};
// Public
return {
extendRobot: function(power, methods) {
Robot.prototype[power] = methods;
},
createRobot: function() {
return new Robot();
}
};
}());
Factory.extendRobot('Speak', {
sayHi: function() {
return 'Hi, ' + this.name;
}
});
var myRobot = Factory.createRobot();
myRobot.name = 'Robin';
myRobot.Speak.sayHi() // => ‘Hi, Robin’
undefined. That's not a problem at all in this case.