Skip to content

Latest commit

 

History

History
36 lines (32 loc) · 1.17 KB

File metadata and controls

36 lines (32 loc) · 1.17 KB


函数也是一个对象

利用这一点有了以下记忆函数的用法 给函数添加了一个属性roles 函数存在则该roles存在
function isPrimary(value) {
    // create cache
    if (!isPrimary.roles) isPrimary.roles = {}
    // cache find
    if (isPrimary.roles[value]) return isPrimary.roles[value]
    // insert role to cache
    isPrimary.roles[value] = value
}
isPrimary('feizao')
console.log(isPrimary.roles) // { feizao: 'feizao' }

IIFE自执行函数
弥补scope上的不足
(fuction() {})()

arguments 类数组结构

方法和函数
play() // 作为函数被调用
feizao.play() //作为方法被调用

this指向调用函数的对象

构造函数返回一个对象则由该构造函数创建的实例对象为返回的对象

const obj0 = { name: 'feizao' }
function _constructor () {
	this.name = 1
	return obj2
}
const obj1 = new _constructor()
console.log(obj1) // obj0