覆盖Backbone.sync但保存它​​的previous功能 [英] Override Backbone.sync but save its previous functionality

查看:115
本文介绍了覆盖Backbone.sync但保存它​​的previous功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写Backbone.sync,但也有我的补充后,原有的Backbone.sync功能运行。我想有点像在Java中的超调用super。有没有一种方法比复制所有的previous code在做到这一点其他的?

I'd like to override Backbone.sync but also have the original Backbone.sync functionality run after my additions. I guess kind of like calling super on a superclass in Java. Is there a way to do this other than copying all the previous code over?

推荐答案

在JavaScript中,可以存储在一个变量的任何属性或方法。下面的例子将分配Backbone.sync另一个变量,然后在你的函数结束与传递给你的新Backbone.sync函数的所有变量调用它。

In JavaScript, you can store any property or method in a variable. The following example will assign Backbone.sync to another variable and then at the end of your function call it with all the variables that are passed to your new Backbone.sync function.

var originalSync = Backbone.sync;
Backbone.sync = function() {
    // Your code here.
    return originalSync.apply(Backbone, arguments);
};

这篇关于覆盖Backbone.sync但保存它​​的previous功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆