zoukankan      html  css  js  c++  java
  • JS_Class.extend

    <script type="text/javascript">
    var Class = {
        create:function(){
            return function(){
                this.init.apply(this,arguments);
                }
            },
        extend:function(current,target,futher){
            for(var i in target.prototype){
                current.prototype[i] = target.prototype[i]
                }
             for(var j in futher){
                current.prototype[j] = futher[j]
                }
            var _init1 = target.prototype["init"],
                _init2 = futher["init"],
                _Parameter1 = _init1.toString().split("(")[1].split(")")[0],
                _Parameter2 = _init2.toString().split("(")[1].split(")")[0],
                _body1 = _init1.toString().split("{")[1].split("}")[0],
                _body2 = _init2.toString().split("{")[1].split("}")[0];
            eval('current.prototype.init=function('+_Parameter1+','+_Parameter2+'){'+_body1+_body2+'}');
            }
        }
    var demo1 = Class.create();
    demo1.prototype = {
        init:function(xinming){
            this.name = xinming
            },
        show:function(){
            alert(this.name)
            }
        }
    var demo2 = Class.create();
    Class.extend(demo2,demo1,{
        init:function(xinbie){
            this.xinbie = xinbie;
            },
        sex:function(){
            alert(this.xinbie)
            }
        });
    new demo2("shao","nan").sex();
    </script>
  • 相关阅读:
    学习进度(第十四周)
    学习进度(第十三周)
    程序员修炼之道阅读笔记03
    程序员修炼之道阅读笔记02
    学习进度(第十二周)
    冲刺进度条10
    冲刺进度条09
    冲刺进度条08
    寒假学习进度报告2
    寒假学习进度报告1
  • 原文地址:https://www.cnblogs.com/somesayss/p/2819888.html
Copyright © 2011-2022 走看看