There are codes which were implemented to show inheritance in Backbone.
GrandParent.js:
define([ "require", "jquery", "backbone"], function(require, $, Backbone) {
return Backbone.Model.extend({
//for method, variable override
name : "grandFa", //@ WILL BE Overrided
familyName : "Song",
age : 99,
sayThis : function() { //@ WILL BE Overrided
alert("GrandParent.this : "+this+" "+this.name);
}
});
});
Parent.js:
define([ "require", "jquery", "backbone", "grandParent"], function(require, $, Backbone, GrandParent) {
return GrandParent.extend({
//for testing complicated this usage
age : 50,
//@Overrided
name : "father",
sayThis : function() {
alert("Parent.this : "+this+" "+this.name);
}
});
});
Main.js:
require.config({
paths : {
jquery : "libs/jquery-2.1.0",
underscore : "libs/underscore-1.6.0",
backbone : "libs/backbone-1.1.0",
grandParent : "1-GrandParent",
parent : "2-Parent"
}
});
require(
["jquery","underscore", "backbone","grandParent","parent","child"], function($, _,Backbone, GrandParent, Parent, Child) {
$(document).ready(function() {
var grandParent = new GrandParent();
var parent = new Parent();
alert(parent.constructor.prototype.name); //=> parent
alert(parent.__proto__.name); //=> parent
});
});
In this code parent.constructor.prototype.name
and parent.__proto__.name
looks totally same. Why did Backbone make 2 fields which works and looks totally same?
Is there any differences in constructor.prototype
& __proto__
?