Last active
February 24, 2017 08:37
-
-
Save surgeboris/29f22c7a821b69ac212fda2054e3a092 to your computer and use it in GitHub Desktop.
Why use "this"? https://medium.com/@surgeboris/thank-you-for-such-an-insightful-post-eric-39b93ef72d47
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
@@ -1,13 +1,13 @@ | |
import Events from 'eventemitter3'; | |
-const rawMixin = function () { | |
+const mixinModel = function (target) { | |
const attrs = {}; | |
- return Object.assign(this, { | |
+ return Object.assign(target, { | |
set (name, value) { | |
attrs[name] = value; | |
- this.emit('change', { | |
+ target.emit('change', { | |
prop: name, | |
value: value | |
}); | |
@@ -19,8 +19,6 @@ const rawMixin = function () { | |
}, Events.prototype); | |
}; | |
-const mixinModel = (target) => rawMixin.call(target); | |
- | |
const george = { name: 'george' }; | |
const model = mixinModel(george); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment