SOURCE

console 命令行工具 X clear

                    
>
console
var obj = {
    name: '张飞'
}

function Person(name) {
    this.name = name
}

Person.prototype = {
    constructor: Person,
    getName: function () {
        console.log(this.name)
    }
}

var person = new Person('jack')

person.getName.call(obj)
person.getName.apply(obj)
var funs = person.getName.bind(obj)
funs()

//call与apply的区别在于参数传递的不同, call函数的参数需要一个一个传递, apply的参数需要传递一个数组。
// bing则返回一个函数,通过执行得到结果


//call 

console.log(Math.max.call(null, 1, 2))
console.log(Math.max.apply(null, [1, 2, 7]))

var arr1 = [1, 2, 3]
var arr2 = [4, 5, 6]

Array.prototype.push.apply(arr1, arr2)
console.log(arr1)

//类数组有哪几种
// arguments dom的对象数组 对象类数组

function args() {
    console.log([...arguments])
    console.log(Array.prototype.slice.call(arguments))
}

args(1, 2, 3, 4)


//手写一个Map

function map(arr, callback) {
    const result = []
    if (!Array.isArray(arr) || !arr.length || typeof callback !== 'function') {
        return []
    }
    for (var i = 0; i < arr.length; i++) {
        result.push(callback(arr[i], i, arr))
    }
    return result
}

console.log(map([1, 2, 3], (item) => {
    return item * 2
}))
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=, initial-scale=">
	<meta http-equiv="X-UA-Compatible" content="">
	<title>call-apply-bind</title>
</head>
<body>
	<div class="name"></div>
	<div class="name"></div>
	<div class="name"></div>
</body>
</html>