Skip to content

Commit

Permalink
adds Object.assign example for dwyl/goodparts#221 #1
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Sep 24, 2016
1 parent b86bd73 commit 9ef0df5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/object.assign.compiled.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions examples/object.assign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var compile = require('google-closure-compiler-js').compile;

var flags = {
jsCode: [{src: `
var user = { name: 'Jack', email: '[email protected]' };
var meta = { height: '185', eyes: 'blue', hair: 'blonde' };
var social = { twitter: 'jackyboy', instagram: 'iamjack' };
// and combine them into a _new_ object with Object.assign:
var jack = Object.assign({}, user, meta, social);
`}],
};
var out = compile(flags);
var filename = __filename.replace('.js', '.compiled.js');
var toSource = require('tosource'); // this is not a Standard! Using just for illustration purposes!
require('fs').writeFileSync(filename, toSource(out.compiledCode));
console.info(out.compiledCode); // will print 'var x = 3;\n'
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"google-closure-compiler-js": "^20160916.0.0",
"install": "^0.8.1",
"npm": "^3.10.8"
},
"devDependencies": {
"tosource": "^1.0.0"
}
}

0 comments on commit 9ef0df5

Please sign in to comment.