Created
March 31, 2017 09:43
-
-
Save ppraksa/4a551f8a1fced467c3f57a2eec0888a2 to your computer and use it in GitHub Desktop.
Typical mixin in js
This file contains 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
Object.prototype.mixin = function(obj) { | |
if(typeof obj === 'object') { | |
for(let i in obj) { | |
String(i) in this ? `${i} - property exist` : this[i] = obj[i]; | |
} | |
} | |
} | |
var Vehicle = { works: true, tank: 100, hasWheels: true } | |
var Car = { works: false, tuning: true } | |
Car.mixin(Vehicle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment