For example:
var Queue = function() {
this.items = [];
};
Queue.prototype.enqueue = function(obj) {
this.items.push(obj);
};
var queue = Object.create(Queue.prototype);
queue.enqueue('src');
Returns:
Uncaught TypeError: Cannot read property 'push' of undefined(…)
Whereas,
var queue = new Queue();
queue.enqueue('src');
works exactly the way I want it to. Is there a key ingredient in calling Object.create() that I am missing in my variable instantiation? Or does the Object.create() method require another pattern for assigning an array to be passed to its prototype objects?
Can someone please explain this minor detail to me because it behooves me to understand why it seems to work in other examples I find online except for my own.. Much appreciated!