1

不幸的是,我四处搜索,但没有找到这个问题的副本。

文件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
   })

如何在不破坏现有属性的情况下扩展继承的属性?

4

1 回答 1

0

看起来你正在使用 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....
  }
});
于 2012-07-20T21:49:27.577 回答