美文网首页javascript
2018-05-03 call apply bind

2018-05-03 call apply bind

作者: wuliduoduo | 来源:发表于2018-05-03 19:51 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
        <script>
            var sum1=Math.max(1,2,3,4,5);
            console.log(sum1);
            var sum2=Math.max.apply(null,[1,2,3,4,5]) //null代表this
            console.log(sum2);
            var sum3=Math.max.call(null,1,2,3,4,5) //apply数组,call参数
            console.log(sum3);
            var sum4=Math.max.bind(null,1,2,3,4,5) //bind相当默认参数
            console.log(sum4());
            console.log(sum4(7,8));
    
            function add(x,y){
                return x+y;
            }
    
            var plus1=add.bind(null,1);
            console.log(plus1(5));
    
            //等价于
            var plus2=function plus1(y){
                return add(1,y)
            }
            console.log(plus2(5))
        </script>
    </body>
    </html>
    

    相关文章

      网友评论

        本文标题:2018-05-03 call apply bind

        本文链接:https://www.haomeiwen.com/subject/aavlrftx.html