JavaScript之 ECMAScript6 新特性


点此查看全部:
http://es6-features.org



Constants
Constants
Support for constants (also known as "immutable variables"), i.e., variables which cannot be re-assigned new content. Notice: this only makes the variable itself immutable, not its assigned content (for instance, in case the content is an object, this means the object itself can still be altered).


const PI = 3.141593
PI > 3.0



//  only in ES5 through the help of object properties
//  and only in global context and not in a block scope
Object.defineProperty(typeof global === "object" ? global : window, "PI", {
    value:        3.141593,
    enumerable:   true,
    writable:     false,
    configurable: false
})
PI > 3.0;






猜你喜欢

转载自lixh1986.iteye.com/blog/2390065