Ember.Application.create vs Ember.Application.extend

Ste*_*vik 5 ember.js ember-cli

我注意到在app.jsEmber CLI(v0.1.12)生成的文件中,他们正在使用:

var App = Ember.Application.extend({...})
Run Code Online (Sandbox Code Playgroud)

但是在介绍指南中,他们正在使用:

window.App = Ember.Application.create({...});
Run Code Online (Sandbox Code Playgroud)

创建Ember应用程序的这两种(创建与扩展)方法之间的结果是否存在差异?

Ore*_*iya 1

正如 Ember 文档中所述,extend 创建一个新的子类,同时 create 创建一个类的实例

主要区别在于通过使用extend

您可以重写方法,但仍然可以通过调用特殊的 _super() 方法来访问父类的实现

create没有那个能力。

链接的文档有专门针对您的问题的良好代码示例。

第 17 行的 create() 创建 App.Soldier 类的实例。第 8 行的extend() 创建了 App.Person 的子类。App.Person 类的任何实例都不会具有 March() 方法。

以及处理该引用的代码。