Skip to content

Instantly share code, notes, and snippets.

@rochapablo

rochapablo/.js

Created Aug 8, 2018
Embed
What would you like to do?
Class to Object
console.clear();
var Track = function(attrs) {
this.icon = (attrs && attrs.icon || 'play_arrow');
this.toggle = (attrs && attrs.toggle || 'close');
this.arrow = (attrs && attrs.arrow || 'keyboard_arrow_down');
this.toObject = function() {
var newObject = {};
for (var prop in this) {
if (this.hasOwnProperty(prop) && typeof this[prop] !== 'function') {
newObject[prop] = this[prop];
}
}
return newObject;
}
};
var track = new Track();
console.log(track.toObject());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.