不幸的是,我四处搜索,但没有找到这个问题的重复项。
文件1:
var Graph = Backbone.View.extend({
move: function() {
//some stuff
}, //more stuff
})
文件2:
define ([ './graph.js' ]), function( graph ) {
var SubGraph = Backbone.View.extend({
// this file needs to inherit what is within the move method but extend it to include other stuff
})
如何在不破坏现有属性的情况下扩展继承的属性?
最佳答案
看起来您正在使用 Require.js
做:
图形模块:
define(function() {
return Backbone.View.extend({
move: function() {
//some stuff
}
});
子图模块:
define(['require', './graph'], function(require) {
var Graph = require('./graph');
return Graph.extend({
// this file needs to inherit what....
}
});
或者,如果您没有定义很多依赖项,则不要包含 require
:
define(['./graph'], function(Graph) {
return Graph.extend({
// this file needs to inherit what....
}
});
关于javascript - 在Javascript中,如何继承和扩展正在继承的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11587224/