I am curious in creating an MVC javascript framework for fun, and as a learning experience.
Inside backbone.js https://github.com/jashkenas/backbone/blob/master/backbone.js the author uses underscore's _.extend()
method to "extend" the backbone object.
Starting with the Model
I am trying to figure out the benefit of this.
// Attach all inheritable methods to the Model prototype.
_.extend(Model.prototype, Events, {});
How does this work? Model
is already defined before this, then the author wants to Copy all of the properties in the source objects over to the destination object
http://underscorejs.org/#extend, he creates a whole bunch of methods inside to interact with the source model as a prototype?
Why not do
Backbone.Model.prototype.get = function() {
return 'Do Get';
}
Backbone.Model.prototype.set = function() {
return 'Do Set';
}
Or better yet use Es6? Is the below even the same as the above??
class Model extends Backbone {
get() {
return 'Do Get';
}
set() {
return 'Do Set';
}
}
Am I on the right path, or am I missing something here? Obviously he created this before es6 was a thing, but I am also curious to know if it could have been done.
My angle is do grasp his intentions and recreate the concept without an underscore dependancy.