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

ES5 方法学习的更多相关文章

  1. 单片机和Linux都想学_换个两全的方法学习单片机

    本节教你如何学习单片机,如何选择合适的开发板和开发工具. 现在我们知道单片机是要学习的,那么怎么去学习单片机?在上一课我们说不要使用老一套的方法学习,实际上是指的两个问题. 第一:选择什么开发板: 第 ...

  2. JavaScript ES6 数组新方法 学习随笔

    JavaScript ES6 数组新方法 学习随笔 新建数组 var arr = [1, 2, 2, 3, 4] includes 方法 includes 查找数组有无该参数 有返回true var ...

  3. java方法学习

    java方法学习 方法概念 什么是方法 方法就是完成某些事情的过程,如:实现两个数相加,用方法add(数值1,数值2). 1.System.out.print(),System是系统的一个类,out是 ...

  4. 用简单的方法学习ES6

    ES6 简要概览 这里是ES6 简要概览.本文大量参考了ES6特性代码仓库,请允许我感谢其作者@Luke Hoban的卓越贡献,也感谢@Axel Rauschmayer所作的[优秀书籍]//explo ...

  5. 常见ES5方法

    • ES5 JSON扩展JSON.parseJSON.stringify • ES5 Object扩展Object.createObject.keys • Date对象Date.now • ES5 F ...

  6. JS数组中every(),filter(),forEach(),map(),some()方法学习笔记!

    ES5中定义了五种数组的迭代方法:every(),filter(),forEach(),map(),some(). 每个方法都接受两个参数:要在每一项运行的函数(必选)和运行该函数的作用域的对象-影响 ...

  7. runtime运行机制方法学习

    runtime这玩意第一次听说时都不知道是什么,经过了解后才知道它就是oc动态语言的机制,没有它那oc就不能称为动态语言.在之前可能大家对runtime了解都不深,随着编程技能的日益加深和需要,大家开 ...

  8. javascript Array 方法学习

    原生对象Array学习 Array.from()   从类似数组的对象或可迭代的对象返回一个数组 参数列表 arraylike  类似数组的对象或者可以迭代的对象 mapfn(可选)   对对象遍历映 ...

  9. zepto.1.1.6.js源码中的each方法学习笔记

    each方法接受要遍历的对象和对应的回调函数作为参数,它的作用是: 1.如果要遍历的对象是类似数组的形式(以该对象的length属性值的类型是否为number类型来判断),那么就把以要遍历的对象为执行 ...

随机推荐

  1. socket 极值数量

    在做Socket 编程时,我们经常会要问,单机最多可以建立多少个 TCP 连接,本文将介绍如何调整系统参数来调整单机的最大TCP连接数. Windows 下单机的TCP连接数有多个参数共同决定,下面一 ...

  2. 启动hbase输出ignoring option PermSize=128m; support was removed in 8.0告警信息

    ./start-hbase.sh starting master, logging to /home/hadoop/hbase-1.2.4/bin/../logs/hbase-hadoop-maste ...

  3. 设计模式之Factory

    设计模式总共有23种模式这仅仅是为了一个目的:解耦+解耦+解耦...(高内聚低耦合满足开闭原则) 介绍: Factory Pattern有3种当然是全部是creational pattern. 1.S ...

  4. zuul进行rate limit

    maven <dependency> <groupId>com.marcosbarbero.cloud</groupId> <artifactId>sp ...

  5. Linux汇编教程01: 基本知识

    在我们开始学习Linux汇编之前,需要简单的了解一下计算机的体系结构.我们不需要特别深入的了解,理解了一些基本概念对与我们理解程序会很有帮助.现在计算机的结构体系都是采用冯诺依曼体系结构的基础上发展过 ...

  6. Android 6.0 Marshmallow root 方法

    android 6.0 已经推出 release 版本了, nexus 5,6,7,9 都放了官方镜像, 本篇文章使用 nexus 6 安装最新的 android 6.0 并进行root step 1 ...

  7. ThinkPHP3.1.3 整合 UEditor百度编辑器 图片上传

    第一步.前端模板实例化百度编辑器 <js file='__ROOT__/Data/UEditor/ueditor.config.js' /> <js file='__ROOT__/D ...

  8. USB 3.1 與 USB Type-C 解釋

    https://tw.transcend-info.com/Support/FAQ-940 以下的內容皆來自上面這個網址. 什麼是USB 3.1? 什麼是USB 3.1? USB 3.1為USB協會制 ...

  9. 实验室项目.md

    1 嵌入式操作系统 为什么要用嵌入式操作系统 普通的单片机编程:程序(软件)--单片机硬件: 嵌入式操作系统开发:程序(软件)--操作系统--嵌入式硬件(包括单片机等); 我们平时普通所学的单片机编程 ...

  10. ASPxTreeList的右键按钮事件

    ASPxTreeList应该是比较长用的控件了~现在就来说说它的右键按钮事件 这里实现的是右键里有折合和展开所有节点的功能 code: <dx:ASPxTreeList ID="ASP ...