原型编程 from ruby

<html>
    <body>

    <script language="javascript">


    function Dog() {     
        this.sit = function () { return "i am sitting"}    
    }


    var dog = new Dog()    // 构建对象,将对象的原型(__proto__)设定为 Dog.prototype, 然后调用Dog函数, 返回新生成的对象, 
    alert (dog.sit())   //将对象设定为this,然后开始调用sit函数
    function MyDog() { }  // 新的子类函数
    MyDog.prototype = new Dog()// 设定子类的元原型为 父类的一个实例。
    var mydog = new MyDog()
    alert(mydog.sit())

    </script>
    </body>

</html>

保存为

你可能感兴趣的:(JavaScript,html,编程,function,Ruby)