ES5

  • Object.create(prototype, descriptors)

      //创建对象
    var o1 = {foo:'bar'};
    var o2 = new Object();
    //Object.create(proto,[descriptors]);
    var o3 = Object.create(null); function Person(name) {
    this.name = name;
    }
    var p1 = new Person('sindy');
    var p2 = Object.create(Person.prototype, {
    age: {
    value: 18,
    writable: false,
    enumerable: false,
    configurable: true,
    //value , writable 和 getter setter函数不能同时设置
    /*get: function () {
    if (typeof age === 'undefined') {
    return 'not set age value yet';
    } else {
    return 'your age:' + age;
    }
    },
    set: function (a) {
    age = a;
    if (this.cTime == 0) {
    console.log('set age OK');
    this.cTime++;
    } else {
    console.log('change age OK');
    }
    }
    },*/
    cTime: {
    value: 0,
    writable: true
    }
    });
  • Object.defineProperty(object, propertyName, descriptor)

      var p1 = new Person('alice');
    Object.defineProperty(p1, 'name', {value:'alice2', writable:true, enumerable: false, configurable: false});
    console.log(p1.name); //=> alice2
    delete p1.name; //=> false configurable==flase,不能defineProperty重定义属性特性
    Object.defineProperty(p1, 'name', {value:'kk', enumerable: true}); //=>error
  • Object.defineProperties(object, descriptors)

    var p1 = new Person('alice');

    Object.defineProperties(p1,{

    skill:{

    value: 'singing',

    writable: true,

    enumerable: true,

    configurable: false

    },

    age: {

    value: 18,

    writable: true,

    enumerable: true,

    configurable: false

    }

    });

    p1.age //18

    p1.skill //singing

  • Object.getOwnPropertyDescriptor(obj, propertyName)

    获取自有属性的descriptor

      function Person (n){ this.name = n; }
    Person.prototype = {
    constructor: Person,
    hi: function(name){ console.log('hi,'+name);}
    };
    var p1 = new Person('alice');
    var nameDescriptor = Object.getOwnPropertyDescriptor(p1, 'name');//=>{value:'alice', enumerable: true, writable: true, configurable: true} var des = Object.getOwnPropertyDescriptor(p1, 'hi');//=>undefined
  • Object.getOwnPropertyNames(obj)

    获取对象所有的自有属性名

      //接上
    p1.age = 11;
    var props = Object.getOwnPropertyNames(p1); //=> ['name', 'age']
  • Object.preventExtensions(obj)

    禁止扩展对象,即不能添加属性到对象上。

      //接上
    Object.preventExtensions(p1);
    p1.home = 'HK';
    console.log(p1.home); //=> undefined
  • Object.isExtensible(obj)

    判断对象是否可扩展

      //接上
    Object.isExtensible(p1);//=> false
  • Object.seal(obj) , Object.isSealed(obj)

    若对象为isSeal状态则不能添加或删除属性, 但可以修改现有属性的值

      //接上
    Object.seal(p1);
    Object.isSealed(p1); //true
    delete p1.name;//=>false
    p1.like = 'shopping';
    console.log(p1.like); //=> undefined
  • Object.freeze(obj) , Object.isFrozen(obj)

    冻结对象(不能添加或删除属性,不能修改现有属性) freeze -> seal -> configurable:false 限制的严格程度递减

      Object.freeze(p1);
    Object.isFrozen(p1); //=> true
    p1.name = 'alice2';
    console.log(p1.name); //=> alice
    p1.school = 'hkzw';
    console.log(p1.school); //=> undefined
  • Object.getPrototypeOf(obj);

    获取对象的原型对象

      var proto = Object.getPrototypeOf(p1);//=>{constructor: Person, hi: function(){..}}
  • Array.isArray(arg)

  • [].indexOf(val,[pos])

  • [].lastIndexOf(val, [pos])

  • [].every(fn(v, i, arr),[context])

  • [].some(fn(v,i, arr), [context])

  • [].forEach(fn(v, i, arr), [context])

  • [].filter(fn(v, i, arr), [context])

  • [].map(fn(v, i, arr), [context]);

  • [].reduce(fn(prev, curr, i, arr), [primitive]);

  • [].reduceRight(fn(prev, curr, i, arr), [primitive]);

  • new Date().toJSON()

    序列化日期对象 输出: "2016-03-14T07:36:09.602Z"

  • String.prototype.trim

    删除字符串两端空格 (" touch ").trim(); => touch

es5 api的更多相关文章

  1. js基础知识温习:构造函数与原型

    构造函数 构造函数主要用于初始化新对象.按照惯例,构造函数名第一个字母都要大写. 构造函数有别于其它函数在于它使用new操作符来调用生成一个实例对象.换句话说,如果一个函数使用new操作符来调用,则将 ...

  2. [Effective JavaScript 笔记]第31条:使用Object.getPrototypeOf函数而不要使用__proto__属性

    ES5引入Object.getPrototypeOf函数作为获取对象原型的标准API,但由于之前的很多js引擎使用了一个特殊的__proto__属性来达到相同的目的.但有些浏览器并不支持这个__pro ...

  3. ES5对Array增强的9个API

    为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...

  4. 关于ES3、ES5、ES6以及ES7所有数组的方法(api)的总结

    起因:工作用经常用到操作数组的方法,这里进行一下总结,我尽量以简洁的语言概括每个方法(api)的作用.如果您想快速定位,可以Control+F 然后搜相应的方法即可定位 :) ES3的数组方法 joi ...

  5. ES5新增数组方法测试和字符串常见API测试

    首先是ES5新增数组方法测试: <!DOCTYPE html><html lang="en"><head> <meta charset=& ...

  6. 学习笔记-es5新增的一些数组的API(不全)-字符串-字符串API(不全)

    ### es5新增的数组的api + indexOf() 搜索数组中的元素,并返回它所在的位置. arr.indexOf(str,index) 参数: str为要查找的字符串 index为开始查找的下 ...

  7. ES5新特性:理解 Array 中增强的 9 个 API

    为了更方便的对JS中Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.index ...

  8. ES5.X相关API和技巧汇总

    https://blog.csdn.net/laoyang360/article/details/77412668

  9. 【转】浅谈JavaScript、ES5、ES6

    什么是JavaScript JavaScript一种动态类型.弱类型.基于原型的客户端脚本语言,用来给HTML网页增加动态功能.(好吧,概念什么最讨厌了) 动态: 在运行时确定数据类型.变量使用之前不 ...

随机推荐

  1. js基础——属性操作

    html属性:属性名——属性值 操作:读 . 写 读操作:用来获取.找到属性名对应的属性值,方法:元素.属性名 例如:var oBtn = document.getElementById('btn1' ...

  2. 加密传输SSL协议4_综合方案

    隔了那么多天终于有时间继续把这个专题做完了,这次一定连续写完这方面的笔记. 上篇博文说明了非对称加密和对称加密各自的优缺点,那么就很自然的衍生出了一种综合的方案. 两种方案的结合--扬长避短 首先发送 ...

  3. python two-dimensional array assignment initialize

    #if you want to initialize a 9*9 two-dimensional array [([""]*9) for i in range(9)] #cauti ...

  4. [php]php时间戳当中关于时区的问题

    PHP_VERSION = 5.5.11 话说php函数 time() 的起始时间戳是从:GMT 1970-01-01 00:00:00 开始算起的 写了点测试代码: $gmt1 = strtotim ...

  5. 【Chromium中文文档】插件架构

    插件架构 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Plugin_A ...

  6. [摘]ASP.Net标准控件(TextBox控件)

    TextBox控件 TextBox控件又称文本框控件,为用户提供输入文本的功能. 1.属性 TextBox控件的常用属性及说明如表1所示. 表1 TextBox控件常用属性及说明 属    性 说   ...

  7. 将Python代码嵌入C++程序进行编写

    将Python代码嵌入C++程序进行编写的实例,python嵌入 把python嵌入的C++里面需要做一些步骤 安装python程序,这样才能使用python的头文件和库 在我们写的源文件中增加“Py ...

  8. Cortex-M3 .s启动文件分析

    1. 基本概念(CMSIS): Cortex Micro-controller Software Interface Standard,微控制器软件接口标准. 2. CMSIS标准的文件结构: a) ...

  9. PHPExcel 多工作表 导入

    //参数初始化 $filePath = ''; if ($_FILES["file"]["error"] > 0) { returnJSON(ERROR_ ...

  10. [Leetcode][Python]33: Search in Rotated Sorted Array

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 33: Search in Rotated Sorted Arrayhttps ...