I have this piece of code in node.js:
'use strict';
var Controller = require('../api/Controller');
var _Promise = require('bluebird');
var BookingController = function(model) {
Controller.call(this);
this.model = _Promise.promisifyAll(model);
};
BookingController.prototype = Object.create(Controller.prototype);
BookingController.prototype.constructor = BookingController;
module.exports = function(model) {
return new BookingController(model);
};
I'm using the Object.create
to inherit all the methods from my SuperController
and I'm using the Controller.call
to inherit this.model
from BookingController
in my SuperController
, everything ok, basic stuff.
What I want know, if it is possible achieve the same effect with normal objects, I will explain:
var SuperObject = {
printName: function() {
console.log(this.name);
}
};
var NormalObject = {
this.name = 'Amanda'
};
console.log(NormalObject.printName) // will print Amanda.
This is possible?
That's exactly what I'm doing with prototype inheritance, but I want do with normal objects.
Other question if you guys can help..
About velocity and performance, what is better use, object inheritance (if possible) or prototype inheritance?
Thanks!