javascript - 在Javascript中,如何继承和扩展正在继承的方法?

标签 javascript oop backbone.js prototype

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

文件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/

相关文章:

Backbone.js - 在模型默认值中使用 new() - 循环引用

javascript - 如何通过 Java Servlet 使用 anchor 标记允许多次下载?

javascript - 创建多个抽象类 javascript ES6

python - 如何在定义类时自动注册一个类

php - Backbone.js 同步 - PHP 返回

jquery - 在单页应用程序中处理 MySql 数据库的最佳方法是什么?

javascript - window.open 在 chrome 扩展弹出窗口中不起作用

javascript - 通过 GAS 提取组中联系人的所有全名 - 循环问题?

javascript - Snap.svg 纸张对象

c# - C#访问父对象的方法