1.使用call的方式

JS 继承的方式

 

2. code如下

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    //继承的第二种实现方式,call方法方式, Function对象中的方法
    function test(str, str2) {
        alert(this.name + ", " + str +  ", " + str2)
    }

    var object = new Object();
    object.name = "zhangsanfeng";
    //test.call相当于调用了test函数
    test.call(object,"ssy","hello"); //将object赋值给this
</script>
</body>
</html>

  

 

 

相关文章:

  • 2021-10-02
  • 2021-11-05
  • 2021-08-21
  • 2021-07-07
  • 2022-03-07
  • 2021-06-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
  • 2021-05-22
  • 2021-04-17
  • 2022-01-25
相关资源
相似解决方案