Last active
October 11, 2015 16:44
-
-
Save wilmoore/72971fc5349fe22ed303 to your computer and use it in GitHub Desktop.
The new JS class syntax is no panacea as it is implied in the video. I mean, there are other ways to fix this: https://youtu.be/05Z6YGiZKmE?t=11m42s
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
'use strict' | |
/*! | |
* exports. | |
*/ | |
module.exports = initialize | |
/*! | |
* object initialization. | |
*/ | |
function initialize () { | |
return Object.assign({ files: { minified: [] } }) | |
} |
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
'use strict' | |
/*! | |
* imports. | |
*/ | |
const infile = require('./infile') | |
/*! | |
* exports. | |
*/ | |
module.exports = initialize | |
/*! | |
* object initialization. | |
*/ | |
function initialize () { | |
return Object.assign(infile(), { addJavaScript }) | |
} | |
/*! | |
* Add JavaScript file. | |
*/ | |
function addJavaScript (data, sourceMap, path) { | |
this.files.minified.push({ data, sourceMap, path }) | |
} |
If I want to follow the "composition over inheritance" principle, should I do this ?
var compose = Object.assign.bind(Object, {})
module.exports = compose(InputFile, {
addJavaScript({ data, sourceMap, path }) {
this._minifiedFiles.push({ data, sourceMap, path })
}
})
I don't think Meteor can handle this
Looks good to me. The only thing to be aware of is if you are supporting older browsers (IE 8/9) you may want to pull in a replacement for Object.assign
and Object.create
since those have spotty or no support for ES5 features. I don't like using big shim libraries but rather like to replace just the functions I know are problematic.
For more info on this concept, check out: https://github.com/wilmoore/polykata/tree/master/oloo-game-player-poc/js
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may prefer it terse:
You may also like ES6 class:
Just keep in mind, ES6 class is not necessary the correct tool for everything.