利用CoffeeScript的`extends`与Backbone.js的`extend`之间的根本区别 [英] Fundamental differences between utilizing CoffeeScript `extends` vs. Backbone.js `extend`

查看:164
本文介绍了利用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:


  1. (最重要的)他们建立 Child.prototype 新的ctor ,其中男星是一个函数,其原型是 Parent.prototype 。它建立原型继承。

  2. 它们全部复制的静态属性到儿童

  3. 他们建立儿童.__ super__ =父。这主要是为了支持CoffeeScript中的红宝石般的超级关键字儿童的方法。

  1. (Most important) They set Child.prototype to new ctor, where ctor is a function whose prototype is Parent.prototype. That establishes prototypal inheritance.
  2. They copy all of Parent's static properties onto Child.
  3. They set Child.__super__ = Parent. This is mainly to support CoffeeScript's Ruby-like super keyword in Child's methods.

这篇关于利用CoffeeScript的`extends`与Backbone.js的`extend`之间的根本区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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