Why ember-cli uses extend instead of create?

Jean

In a new ember App you write first:

var App = Ember.Application.create({
    test: 'foo',
    ...
});

In a new ember-cli App you write first:

var App = Ember.Application.extend({
    test: 'foo',
    ...
});

Why?

( In the second case, I can't read a global property (App.test) from a controller. !? )

bguiz

This question actually has a lot to do with Ember.Object.

.extend() creates a new class that extends the old one, with class-level properties defined in the hash that is passed in.

.create() create a new instance of the class, with object-level properties defined in the hash that is passed in.

This is why you cannot read the property in the second case. If you want to do that, you will need to do:

var App = Ember.Application.extend({});
App.test = 'foo';

In a plain Ember app, you can create an instance of the App object, because you are going to use it directly.

In an ember-cli generated Ember app, you do not create an instance of the App object, you merely define its class (using .extend()). This is because you do not use it directly, as ember-cli wants the class, so that it may do its own things to it, before it internally instantiates it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why Collections.sort uses merge sort instead of quicksort?

Why "System.arraycopy" uses "Object" instead of "Object[]"?

Why Rails 5 uses ApplicationRecord instead of ActiveRecord::Base?

Why is my ember-cli build time so slow on windows?

Ember-CLI without Ember Data, use plain ember object instead

Ember.Application.create vs Ember.Application.extend

How to extend an ember-cli addon?

Create a for loop that will iterate a certain number of times in Ember-CLI

Configure CSP in an Ember CLI application which uses http-mock

haskell quick sort, why the first let uses <= instead of <?

Why does Ember installs everything as devDependencies instead of normal dependency

Why Swift library uses "enum CommandLine" instead of "struct CommandLine"?

Why the linux kernel uses double logical negations instead of casts to bools?

Why Python uses global variables instead of method parameters?

How to create a object in ember-cli-mirage?

Why std::get uses template parameter instead of regular parameter?

Why Ubuntu uses eglibc instead of glibc?

How to create SSLStream which uses Ssl3 instead of Tls

Create shim for ember-cli

How do I create a relationship in ember-cli-mirage?

Default layout for ember-cli, instead of "UnrecognizedURLError

Create base class for controller to extend/inherit in Ember application

Why Hadoop uses Kerberos instead of PKI/OAuth for authentication?

Why not logistic regression uses multiplication instead of addition for error matrix?

How do you create an ajax service in ember-cli 3.17?

Why extend class instead of conforming to a protocol?

Why does Typescript uses 'number' instead of int'?

Why Android Studio uses Java classes instead of Kotlin

Why the method uses Activator.CreateInstance instead of directly "new Class()"?