admin管理员组文章数量:1321425
If you have a look at Backbone.js's source code, you'll see multiple uses of this pattern:
this.initialize.apply(this, arguments);
For example, here:
var Router = Backbone.Router = function(options) {
options || (options = {});
if (options.routes) this.routes = options.routes;
this._bindRoutes();
this.initialize.apply(this, arguments);
};
Why not just write this.initialize(arguments)
instead?
If you have a look at Backbone.js's source code, you'll see multiple uses of this pattern:
this.initialize.apply(this, arguments);
For example, here:
var Router = Backbone.Router = function(options) {
options || (options = {});
if (options.routes) this.routes = options.routes;
this._bindRoutes();
this.initialize.apply(this, arguments);
};
Why not just write this.initialize(arguments)
instead?
1 Answer
Reset to default 8this.initialize.apply(this, arguments)
Works like this:
this.initialize(arguments[0], arguments[1], arguments[2], ...)
Each item in arguments is passed as a parameter to initialize()
Which is very different from just:
this.initialize(arguments)
Pass arguments
as the first and only parameter to initialize()
In other words, if the function expects an array as the first parameter, use this.initialize(arguments)
, otherwise use .apply()
.
本文标签:
版权声明:本文标题:javascript - this.initialize(arguments) vs this.initialize.apply(this, arguments): what's the difference? - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742102604a2420869.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论