JavaScript的继承(Ajax基础教程)

. 运用 prototype 属性
    定义对象   A:
    function A() { ... }
    A 添加属性或方法 
    A.prototype.aa
    A.prototype.bb = function() { ... }
    创建一个对象继承 A 对象
    function B() {}
    B.prototype = new A();
    重写 A 对象的 bb 方法
    B.prototype.bb = function() { ... }
. 对象属性的复制
     function createInheritance( parent, child ) {
        var property;
        for( property in parent ) {
           if( !child[ property ] ){
             child[ property ] = parent[ property ];
           }
        }
     }
注:私有属性
  用 var 在构造函数中定义的变量或在其内部定义的 function
  可以用 this 关键词定义特权函数 ( privileged function ) 来访问.
   function A()
        {
            var aa;
            function bb() { ... }
            this.cc() { bb(); }
         }

转载于:https://www.cnblogs.com/Hawk-Hong/archive/2006/07/05/443396.html

你可能感兴趣的:(JavaScript的继承(Ajax基础教程))