利用CoffeeScript的`extends`与Backbone.js的`extend`之间的根本区别 [英] Fundamental differences between utilizing CoffeeScript `extends` vs. Backbone.js `extend`
本文介绍了利用CoffeeScript的`extends`与Backbone.js的`extend`之间的根本区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是使用之间的根本区别的CoffeeScript 扩展
与Backbone.js的延长
?
What are the fundamental differences between utilizing CoffeeScript extends
vs. Backbone.js extend
?
例如,如何为
class User extends Backbone.Model
从
User = Backbone.Model.extend()
推荐答案
两个旨在是等价的。引述Backbone.js的更新日志:
The two are intended to be equivalent. To quote the Backbone.js changelog:
0.3.0:主干课程可现在CoffeeScript的类无缝地继承
0.3.0: Backbone classes may now be seamlessly inherited by CoffeeScript classes.
这两个CoffeeScript中的儿童伸出父
和骨干的儿童= Parent.extend()
做三个重要的事情:
Both CoffeeScript's Child extends Parent
and Backbone's Child = Parent.extend()
do three important things:
- (最重要的)他们建立
Child.prototype
到新的ctor
,其中男星
是一个函数,其原型是Parent.prototype
。它建立原型继承。 - 它们全部复制
父
的静态属性到儿童
。 - 他们建立
儿童.__ super__ =父
。这主要是为了支持CoffeeScript中的红宝石般的超级
关键字儿童
的方法。
- (Most important) They set
Child.prototype
tonew ctor
, wherector
is a function whose prototype isParent.prototype
. That establishes prototypal inheritance. - They copy all of
Parent
's static properties ontoChild
. - They set
Child.__super__ = Parent
. This is mainly to support CoffeeScript's Ruby-likesuper
keyword inChild
's methods.
这篇关于利用CoffeeScript的`extends`与Backbone.js的`extend`之间的根本区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文