Luke The Obscure
Luke The Obscure

Reputation: 1524

Access parent constructor in Ember.js object

In Ember.js, how do I access the parent objects constructor? I did find this while poking around:

this.__ember_meta__.proto.__proto__.__proto__.constructor

Which yields the correct value, but that's unacceptable for reasons which should be obvious.

Looking at the code in the extend() method, it looks like it's assigning the parent class to a property named superclass, but I'm not seeing that in my classes for some reason.

Upvotes: 0

Views: 506

Answers (1)

JLRishe
JLRishe

Reputation: 101652

Looking at the definition of the extend method, you can see it building up and returning a variable called Class. You should picture your methods as running on an instance of that Class (meaning that this.prototype === Class.prototype).


With that in mind, you can see that this Class itself is being assigned to Class.prototype.constructor:

proto = Class.prototype = o_create(this.prototype); 
proto.constructor = Class; 


So you can access this Class using this.constructor, and furthermore, the constructor of the parent class is being (as you noted) assigned to the .superclass property of Class:

Class.superclass = this;


So I believe that the answer you seek is simply:

this.constructor.superclass

Observe: http://jsfiddle.net/99gvpqzx/1/

Upvotes: 1

Related Questions