Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

document the init function for Ember.CoreObject

  • Loading branch information...
commit aedbf8b2092fb03e1e71105054ce3c5a010e7cd2 1 parent 91b1dc1
Stanley Stuart fivetanley authored

Showing 1 changed file with 39 additions and 0 deletions. Show diff stats Hide diff stats

  1. +39 0 packages/ember-runtime/lib/system/core_object.js
39 packages/ember-runtime/lib/system/core_object.js
@@ -161,6 +161,45 @@ CoreObject.PrototypeMixin = Mixin.create({
161 161
162 162 isInstance: true,
163 163
  164 + /**
  165 + An overridable method called when objects are instantiated. By default,
  166 + does nothing unless it is overridden during class definition.
  167 +
  168 + Example:
  169 +
  170 + ```javascript
  171 + App.Person = Ember.Object.extend({
  172 + init: function() {
  173 + alert('Name is ' + this.get('name'));
  174 + }
  175 + });
  176 +
  177 + var steve = App.Person.create({
  178 + name: "Steve"
  179 + });
  180 +
  181 + // alerts 'Name is Steve'.
  182 + ```
  183 +
  184 + NOTE: If you do end override init for a framework class like `Ember.View` or
  185 + `Ember.ArrayController`, be sure to call `this._super()` in your
  186 + `init` declaration! If you don't, Ember may not have an opportunity to
  187 + do important setup work, and you'll see strange behavior in your
  188 + application.
  189 +
  190 + ```javascript
  191 + App.PersonController = Ember.ArrayController.extend({
  192 + // called when Ember sets up an instance of your PersonController,
  193 + // or when created using App.PersonController.create()
  194 + init: function(){
  195 + this._super();
  196 + alert('This is how you override init');
  197 + }
  198 + });
  199 + ```
  200 +
  201 + @method init
  202 + */
164 203 init: function() {},
165 204
166 205 /**

0 comments on commit aedbf8b

Please sign in to comment.
Something went wrong with that request. Please try again.