Object


1. Object.getPrototypeOf(o)
获取对象的prototype对象。等价于以前的o.__proto__

var o = {};
Object.getPrototypeOf(o) === o.__proto__; // true

2. Object.getOwnPropertyNames(o)
获取自有属性名列表。结果列表将不包含原型链上的属性。

var o = { bar: 42, a: 2, b: 3};
Object.getOwnPropertyNames(o); // ["bar", "a", "b"] var o = {}
o.__proto__.b = 2;
Object.getPrototypeOf(o).c = 3; // 和上面的一句等价
Object.getOwnPropertyNames(o); // []

3. Object.keys

返回对象o的所有可枚举(enumerable)属性的名称。
和 Object.getOwnPropertyNames 区别如下:

var o = {};
// 属性 b 不可枚举
Object.defineProperty(o, 'b', {
value: 1
});
o.b; //
Object.keys(o); // []
Object.getOwnPropertyNames(o); // ["b"]

4. Object.create(proto[, propertiesObject])
The Object.create() method creates a new object with the specified prototype object and properties.
第1个参数是该对象的 prototype, 第2个参数和 Object.defineProperties 第2个参数类似
详见链接;

5. Object.assign
有点像 $.extend 方法, 但是是浅复制

// 复制
var o = {a: 1};
var copy = Object.assign({}, o);
copy.a; //
copy.a = 2;
copy.a; // // 复制
var o1 = {a: 1};
var o2 = {b: 2};
var copy = Object.assign({}, o1, o2);
copy.a; //
copy.b; // // 浅复制
var o = {a: {b: 1}};
var copy = Object.assign({}, o);
copy.a.b; //
copy.a.b = 2;
o.a.b; // // 只复制 可枚举的
var obj = Object.create({ foo: 1 }, { // foo is on obj's prototype chain.
bar: {
value: 2 // bar is a non-enumerable property.
},
baz: {
value: 3,
enumerable: true // baz is an own enumerable property.
}
});
var copy = Object.assign({}, obj);
copy.bar; // undefined;
copy.baz; //

5. Object.prototype.isPrototypeOf(v)

检查对象是否是位于给定对象v的原型链上。

var o = {};
var q = Object.create(o);
o.isPrototypeOf(q);

6. Object.defineProperty(obj, prop, descriptor)

obj 对象, prop 属性名, descriptor 属性值和描述
详见链接;

7. Object.defineProperties(obj, props)

根据对象描述props来定义对象o,通常props包含多个属性的定义。
比 Object.defineProperty 更实用, 因为可以定义多个属性

var obj = {};
Object.defineProperties(obj, {
'property1': {
value: true,
writable: true
},
'property2': {
value: 'Hello',
writable: false
}
// etc. etc.
});

8. Object.getOwnPropertyDescriptor(o,p)

获取对象描述

The Object.getOwnPropertyDescriptor() method returns a property descriptor for an own property (that is, one directly present on an object and not in the object's prototype chain) of a given object.

var o = { get foo() { return 17; } };
var d = Object.getOwnPropertyDescriptor(o, 'foo');
// d is {
// configurable: true,
// enumerable: true,
// get: /*the getter function*/,
// set: undefined
// } var o = { bar: 42 };
var d = Object.getOwnPropertyDescriptor(o, 'bar');
// d is {
// configurable: true,
// enumerable: true,
// value: 42,
// writable: true
// }

9. Object.seal(o)

seal 单词的意思是
n. 印章,海豹
v. 封闭,密封

The Object.seal() method seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable. Values of present properties can still be changed as long as they are writable.

设置以后不可添加新属性和修改已有属性的特性,但是可以修改已有的属性

var o = {a: 1, b:2};
var obj = Object.seal(o);
obj === o; // true, 注意它们是全等的
Object.isSealed(obj); // true
Object.isFrozen(obj); // false
o.c = 222;
o.c; // undefined
o.a = 2;
o.a; // Object.defineProperty(obj, 'ohai', {
value: 17
}); // Uncaught TypeError: Cannot define property:ohai, object is not extensible. Object.defineProperty(obj, 'a', {
value: 17
});
o.a; // Object.defineProperty(obj, 'a', {
writable: true
}); // Uncaught TypeError: Cannot redefine property: a // 这样不会报错, 因为没有修改
Object.defineProperty(obj, 'a', {
writable: false
});

10. Object.isSealed(o);
判断一个对象是否sealed

var obj = {};
Object.defineProperties(obj, {
'property1': {
configurable: false
}
});
Object.preventExtensions(obj);
Object.isSealed(obj); // true

11. Object.freeze(o)

和 Object.seal 限制一样,并且还不能修改原来的属性

var o = {a: 1, b:2};
var obj = Object.freeze(o);
obj === o; // true, 注意它们是全等的
Object.isSealed(obj); // true
Object.isFrozen(obj); // true
obj.a = 22;
obj.a; //
obj.c = 22;
obj.c; // undefined;
Object.isFrozen(obj); // true
Object.defineProperty(obj, 'a', {
writable: true
}); // Uncaught TypeError: Cannot redefine property: a

12. Object.isFrozen(o)

判断一个对象是否 frozen

var obj = {};
Object.defineProperties(obj, {
'property1': {
configurable: false,
writable: false
}
});
Object.preventExtensions(obj);
Object.isFrozen(obj); // true

13. Object.preventExtensions(o)

将对象置为不可扩展。

var obj = {};
var o = Object.preventExtensions(obj);
o === obj;
o.a = 1;
o.a; // undefined
Object.isExtensible(o); // true

14. Object.isExtensible(o)

判断一个对象是否可扩展, 默认为 false

15. Object.prototype.propertyIsEnumerable(p)

检查一个对象上的属性p是否可枚举。

var o = {}
Object.defineProperties(o, {
a: {
enumerable: false
},
b: {
enumerable: true
}
});
o.propertyIsEnumerable('a'); // false
o.propertyIsEnumerable('b'); // true

16. Object.getOwnPropertySymbols

待描述;

17. Object.is

判断2个值是否相等

NaN == NaN; // false
NaN === NaN; // false
Object.is(NaN, NaN); // true // Special Cases
Object.is(0, -0); // false
Object.is(-0, -0); // true
Object.is(NaN, 0/0); // true

Array


详情请点链接

String


1. String.prototpye.trim

去掉字符串两头的空白符和换行符。

2. 字符订阅

//property access on strings
"abc"[1] === "b"; // 相当于 "abc".charAt(1)

Function


Function.prototype.bind(thisTarget, arg1,…argn)

JSON


JSON.parse(text)
JSON.stringify(obj)

Date


1. Date.now
获取当前时间距1970.1.1 00:00:00的毫秒数。
Date.now(); //1492351123908

2. Date.prototype.toISOString
根据ISO860123生成时间字符串。
(new Date).toISOString(); // "2017-04-16T09:01:23.366Z"

参考链接:

http://pij.robinqu.me/JavaScript_Core/ECMAScript/es5.html

MDN Object

最新文章

  1. 微软开源 WCF 分布式服务框架,并入 .NET 基金会项目
  2. java分享第十三天(fastjson生成和解析json数据,序列化和反序列化数据)
  3. apache解析多个域名
  4. 关于C++虚函数的一点点~~
  5. const 放在函数后
  6. CodeForces 656B
  7. 加链接太麻烦?使用 linkit 模块提升用户编辑体验
  8. Flash图表控件FusionCharts如何定制图表中的趋势线和趋势区
  9. 关于ASP.NET控件方面的学习(恢复版)
  10. WebKit JavaScript Binding添加新DOM对象的三种方式
  11. C++实现发送HTTP请求
  12. ECSHOP_百度收录网址后面有?from=rss
  13. PHP搭建(windows64+apache2.4.7+mysql-5.6+php5.5)
  14. 学习window系统下的注册表
  15. 从项目中总结的js知识点
  16. 【Java集合源代码剖析】LinkedHashmap源代码剖析
  17. captcha.js一个生成验证码的插件,使用js和canvas生成
  18. WMI参数介绍
  19. [ Build Tools ] Repositories
  20. Python FTP文件传输

热门文章

  1. UIScrollView---iOS-Apple苹果官方文档翻译
  2. 【洛谷 P3809】 【模板】后缀排序
  3. centos6.5下安装svn并且实现多项目管理配置方案
  4. [bzoj1005][HNOI2008]明明的烦恼-Prufer编码+高精度
  5. 简易微信小程序签到功能
  6. Fetch-新一代Ajax API
  7. poj 3104 Drying(二分查找)
  8. js中的document.ready
  9. linux下pthread_cancel无法取消线程的原因【转】
  10. 移动端测试===Android内存泄露和GC机制(转)