zoukankan      html  css  js  c++  java
  • javascript关于继承的方法

    <script type="text/javascript">

    /*//继承的第一种方式:对象冒充
    function parent(username){
        this.username=username;
        
        this.sayhello=function(){
            alert(this.username)
            }
        }
    function child(username,password){
        //下面三行代码最关键
        this.method=parent;

        this.method(username);
        this.password=password;
        
        this.sayword=function(){
            alert(this.password);
            }
        }
    var parent= new parent("zhangsan");
    var child=new child("lishi","123");
    parent.sayhello();
    child.sayhello();
    child.sayword();*/

    /*//继承第二种方法:call方法方式,function 对象的中方法
    function test(str){
        alert(this.name+str);
        }
    var object=new Object();
    object.name="zhangsan";

    //this.call相当于调用test函数
    test.call(object,"ningkangchun");//将object赋给了this*/
    //使用原形链(prototype chain)方法实现对象的继承

    </script>

  • 相关阅读:
    Javascript
    CSS3新增特性HTML标签类型
    HTML5新增的标签
    prototype __proto__ Function
    oninput
    extend
    hasOwnProperty()
    this prototype constructor
    Array类型判断
    指针
  • 原文地址:https://www.cnblogs.com/baikaishui/p/2342469.html
Copyright © 2011-2022 走看看