Created
May 28, 2018 20:43
-
-
Save jasonhofer/76f378650d3830251b938d25352bd1e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ember.Object.keys = function (obj) { | |
if (!(obj instanceof Ember.Object)) { | |
return Object.keys(obj); | |
} | |
if (obj instanceof DS.Model) { | |
return Object.keys(obj.toJSON()); | |
} | |
let constructor = obj.constructor, | |
objectKeys = [], | |
rx = /^[a-z][a-z0-9_]*$/i; | |
while (constructor && constructor.prototype) { | |
objectKeys.push(Object.keys(constructor.prototype)); | |
constructor = constructor.superclass; | |
} | |
return _.difference( | |
[].concat(...objectKeys.reverse()), | |
Object.keys(Ember.Object.prototype) | |
).filter(key => rx.test(key)); | |
}; | |
Ember.Object.ownKeys = function (obj) { | |
let rx = /^[a-z][a-z0-9_]*$/i; | |
return _.difference( | |
Object.keys(obj.prototype || obj.constructor.prototype), | |
Object.keys(Ember.Object.prototype) | |
).filter(key => rx.test(key)); | |
}; | |
Ember.Object.toJSON = function (obj) { | |
if (!(obj instanceof Ember.Object)) { | |
throw Error('Ember.Object.toJSON() expects an instance of Ember.Object'); | |
} | |
if (obj instanceof DS.Model) { | |
return obj.toJSON(); | |
} | |
return obj.getProperties(Ember.Object.keys(obj)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment