18-2-call和apply

时间:2019-09-07
本文章向大家介绍18-2-call和apply,主要包括18-2-call和apply使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body {
            font-family: "Microsoft YaHei", serif;
        }

        body, dl, dd, p, h1, h2, h3, h4, h5, h6 {
            margin: 0;
        }

        ol, ul, li {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        img {
            border: none
        }
    </style>
</head>
<body>

<script>
    // function a() {
    //     console.log(1);
    //     console.log(2);
    //     console.log(this);
    // }
    // a();
    // a.call(document);
    // call第一个实参是this的指向

    // function a(x,y) {
    //     console.log(x);
    //     console.log(y);
    //     console.log(this);
    // }
    // a.call(document,x,y)

    // appl的使用
    // function a(x,y) {
    //     console.log(x);
    //     console.log(y);
    //     console.log(this);
    // }
    // a.apply(document,[img,9])

    function a() {
        alert(this)
    }
</script>
</body>
</html>

原文地址:https://www.cnblogs.com/zhangyu666/p/11479974.html