Object.getOwnPropertyDescriptor(obj, prop)
:
a property has either a value
and three boolean attributes writable
,
enumerable
and configurable
, or a get
-ter and a set
-ter.
{
value: "foo",
writable: true, // You can modify the value.
enumerable: true, // Will appear in a "for (var i in obj.prop)".
configurable: true // You can change "writable", "enumerable" and
// "configurable"
}
Object.defineProperty(obj, prop, desc)
: set the property descriptor (as seen
above).
Object.defineProperty(obj, 'answer', {
get: function() { return 42; },
set: function() { throw Error('Truth is immutably 42'); }
});
Object.defineProperties(obj, props)
: same as above.
Object.defineProperties(obj, {
'prop1': {value: 1337, writable: false},
'prop2': {value: 666, enumerable: false}
});
Object.keys(obj)
: array of strings of all enumerable properties.
Object.getOwnPropertyNames(obj)
: array of strings of all properties
(including non-enumerable ones).
Object.create(proto, props)
: inherit a new object from the object proto
.
var mum = Object.create({}, {common: {value:5}, overriden: {value:7}});
var baby = Object.create(mum, {overriden: {value:8}});
Object.getPrototypeOf(obj)
: self-descriptive.
Object.preventExtensions(obj)
: now you can't add properties to obj
.
Object.isExtensible(obj)
Object.seal(obj)
: now you can't delete or add any properties, and you can't
change their descriptors (but you can change their values).
Object.isSealed(obj)
Object.freeze(obj)
: now you can't delete, add, or change any property.
Object.isFrozen(obj)
arr.indexOf(searchElement [, fromIndex])
arr.lastIndexOf(...)
arr.every(callbackfn [, thisArg])
arr.some(callbackfn [, thisArg])
arr.forEach(callbackfn [, thisArg])
arr.map(callbackfn [, thisArg])
arr.filter(callbackfn [, thisArg])
arr.reduce(callbackfn [, initialValue])
arr.reduceRight(...)
How to use it? Write the following instruction:
"use strict";
What does it do?
var
to introduce new variables.eval
function.eval
.arguments.caller
and arguments.callee
.with
statements become a syntax error.JSON.parse('{"some": "data"}')
→ {some: "data"}
JSON.stringify({foo:undefined, bar:null})
→ '{"bar":null}'
"\t Foo! ".trim()
→ "Foo!"
func.bind(thisArg)
: returns a function that runs func
, with this
bound
as thisArg
.Standard available at ECMA.
My dearest thanks go to Brendan Eich, Allen Wirfs-Brock, Douglas Crockford, Mark Miller, Tom Van Cutsem, Alex Russell, and so many others.