Skip to content

Instantly share code, notes, and snippets.

@ppraksa
Created March 31, 2017 09:43
Show Gist options
  • Save ppraksa/4a551f8a1fced467c3f57a2eec0888a2 to your computer and use it in GitHub Desktop.
Save ppraksa/4a551f8a1fced467c3f57a2eec0888a2 to your computer and use it in GitHub Desktop.
Typical mixin in js
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