Created
December 22, 2015 12:22
-
-
Save eagleflo/e5285ee55d21aa01787c to your computer and use it in GitHub Desktop.
const & Object.freeze in ES
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
$ babel-node | |
> const foo = [] | |
'use strict' | |
> foo.push(1, 2, 3) | |
3 | |
> foo | |
[ 1, 2, 3 ] | |
> Object.freeze(foo) | |
[ 1, 2, 3 ] | |
> foo.push(4, 5, 6) | |
repl:3 | |
foo.push(4, 5, 6); | |
^ | |
TypeError: Can't add property 3, object is not extensible | |
at repl:3:5 | |
at Object.exports.runInThisContext (vm.js:54:17) | |
at _eval (/usr/local/lib/node_modules/babel/lib/_babel-node.js:86:26) | |
at REPLServer.replEval (/usr/local/lib/node_modules/babel/lib/_babel-node.js:169:14) | |
at bound (domain.js:287:14) | |
at REPLServer.runBound [as eval] (domain.js:300:12) | |
at REPLServer.<anonymous> (repl.js:417:12) | |
at emitOne (events.js:77:13) | |
at REPLServer.emit (events.js:169:7) | |
at REPLServer.Interface._onLine (readline.js:210:10) | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment