Skip to content

call,apply,bind #9

@aicekiller

Description

@aicekiller

都属于Function构造函数原型上的方法Function.prototype

用途

call()调用一个函数,其具有一个指定的this值和参数列表。
apply()调用一个函数,其具有一个指定的this值,以及作为一个数组(或类似数组的对象)提供的参数。

var arr = [1,10,2,8];
Math.max.call(Math,...arr);
Math.max.apply(Math,arr);

bind()创建一个新函数,当调用时,将其this关键字设置为提供的值,在调用新函数时,在任何提供之前提供一个给定的参数序列。
callapply都是为了动态改变this,当一个object没有某个方法,

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions