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.
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/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.