LoginSignup
9
8

More than 5 years have passed since last update.

現状

大文字で書かれている物は弄らない。

ALLCAPS = 'this is a constant, please don't mess with it'

const宣告

Firefox、Chrome/node.js(V8)に実装され、ECMAScript Harmonyにも提案されてる仕様です。

const は Mozilla 特有の拡張であり、IE ではサポートされていませんが、Opera ではバージョン 9.0 からサポートされました。-MDN

注:coffee-scriptでconstはリザーブされでます。

const foo = 'bar';

accessor methodによる偽装

人によれば邪道、又はアンチパターンですが、面白半分で書いてみた。

k = {}

Object.defineProperty k, 'foo', { value: 'bar', writable: false}

console.log k.foo
# bar

k.foo = '' # 上書き出来ません
console.log k.foo
# bar

Object.defineProperty k, 'foo', { value: 'fuga', writable: false}
# Error: Attempting to change value of a readonly property.

ブラウザとの相性
browser support

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8