JavaScript 进阶二 内置对象

作者 Marlous 日期 2018-07-07
JavaScript 进阶二 内置对象

一 简介

简介
内容
以下“常用方法”指“常用的原型方法”。

二 Object

  1. 概念:
    Object

  2. 常用方法:

  • Object.create
    Object.create

  • Object.prototype.toString
    Object.prototype.toString

  • Object.prototype.hasOwnProperty
    判断一个属性是自身属性,还是原型链上的属性。
    Object.prototype.hasOwnProperty

三 String、Number、Boolean

1 Boolean

  1. 概念:
    Boolean

  2. 其他类型向布尔型转换:
    其他类型向布尔型转换

2 String

  1. 概念:
    String

  2. 常用方法:

  • String.prototype.indexOf
    String.prototype.indexOf

  • String.prototype.replace
    String.prototype.replace

  • String.prototype.split
    String.prototype.split

3 Number

  1. 概念:
    Number

  2. 常用方法:

  • Number.prototype.toFixed
    Number.prototype.toFixed

四 Array

  1. 概念:
    Array

  2. 常用方法:

  • Array.prototype.splice
    Array.prototype.splice

  • Array.prototype.forEach
    Array.prototype.forEach

五 Function

  1. 概念:
  • Function

  • 自定义对象构造器:
    自定义对象构造器

  1. 常用方法:
  • Function.prototype.apply
    Function.prototype.apply

  • Function.prototype.bind
    通过把返回值赋给变量 circlemove,然后用 setTimeout 函数让点推迟一定时间移动。
    Function.prototype.bind

  1. 子类构造器:
    子类构造器

  2. 函数调用的三种方式:

  • ()
  • apply,call 。指定函数调用者和参数。
  1. 函数参数特点:
    形参个数不一定等于实参个数。
    值传递。
    通过参数类型检查实现函数重载。

  2. arguments
    arguments 对象是在函数执行时函数内部生成的。
    arguments

  3. 值传递:
    值传递

六 RegExp、Date、Error

1 RegExp

  1. 概念:
    RegExp

  2. 常用方法:

  • RegExp.protorype.test
    RegExp.protorype.test

2 Date

  1. 概念:
    Date

3 Error

N/A

七 Math、JSON

1 Math

  1. 概念:
    Math

  2. 常用方法:

  • Math.floor
    Math.floor

  • Math.random
    Math.random

2 JSON

  1. 概念:
    JSON

  2. 常用方法:

  • JSON.stringify
    JSON.stringify

  • JSON.parse
    JSON.parse

八 全局对象

  1. 概念:
    全局对象

  2. 几个重要的属性和方法:

  • NaN
    NaN

  • parseInt
    parseInt

  • eval
    示例代码,将字符串转成 JSON 对象。
    通常不建议使用此函数。
    eval

  • encodedURIComponent
    encodedURIComponent