Blogger Information
Blog 13
fans 0
comment 0
visits 12525
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
apply、call、bind的使用
so的博客
Original
600 people have browsed it

函数原型

apply(context,array): 第二个参数是数组,可以是Array或arguments对象

call(context,num1,num2...):参数必须一一列举出来

bind(context,num1,num2...): 返回一个函数

每个函数都包含apply和call两个非继承而来的方法,context表示运行函数的作用域


 

function sum(num1,num2){
           return num1+num2;
       }
       function callSum(num1,num2){
           return sum.call(this,num1,num2);
       }
       function applySum(num1,num2){
           return sum.apply(this,arguments);
       }
       function bindSum(num1,num2){
           return sum.bind(this,num1,num2)();
       }
       console.log(callSum(1,2)); // 3
       console.log(applySum(2,3)); //5
       console.log(bindSum(3,4)); //7




Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post