zoukankan      html  css  js  c++  java
  • js34

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <script type=text/javascript charset=utf-8>
            (function(){
                //2中函数声明的区别
                add(1,1);
                function add(x,y){
                    alert(x+y)
                }
                add(1,2);
                
                //add2(12,3)//不能调用
                var add2 = function(x,y){
                    alert(x+y)
                }
                add2(12,3)
    
    
                //传值还是传址,string是基础类型,
                var i = 100;
                var s = "one";
                function add3(i,s){
                    i++;
                    s+="--"
                }
                alert(i);//100 or 101
                alert(s);//"one" 
            })()
            
            
            var a = 3;
            var b = [a];
            alert(b instanceof Array);
            alert(b[0]);
    
    
            var a = "[1,2,3,4,5]";
            var array = eval(a);//string变数组
            for (var i = 0; i < array.length; i++) {
                alert(array[i])
            }
    
            //解析成函数,并且调用
            var str = "var show = function(){alert(100)}()";
            eval(str);
    
            new person().showName();
            var cat = {};
            Object.getPrototypeOf(cat).name = "MAOMI";
            cat.__proto__.master = "USPCAT.COM";
    
            var a = {};//空类
            a.__proto__ = person.prototype;
    
            var b = {};
            b.__proto__ = new person();
            b.__proto__.constructor = b;
    
    
            
            var JSON = {};
    
            JSON.prototype = {
                toJSONString :function(){
                    var outPut = [];
                    for(key in this){
                        outPut.push(key+" -- "+this[key])
                    }
                    return outPut;
                }
            }
    
            function mixin(receivingClass,givingClass){
                for(methodName in givingClass.prototype){
                    //本类中没有这个函数的情况下我在聚合,否则跳过
                        receivingClass.prototype[methodName] = givingClass.prototype[methodName]
                }
            }
    
            var o = function(){
                this.name = "YUN";
                this.age = 17
            }
    
            mixin(o,JSON);
            alert(JSON.prototype.toJSONString);
            alert(o.prototype.toJSONString);
            var a = new o();
            alert(a.toJSONString());
    
    
            JSON.prototype['toJSONString'] = function(){
                var outPut = [];
                for(key in this){
                    outPut.push(key+" ------ "+this[key])
                }
                return outPut;
            }
    
            mixin(o,JSON);
            alert(JSON.prototype.toJSONString);
            alert(o.prototype.toJSONString);
            alert(a.toJSONString()); 
    
            </script>
        </head>
        <body>
        </body>
    </html>
    /**
     * 掺元类
     * 有的适合只需要继承一个类(几个)中的一些函数
     * 
     */
    (function(){
        //我们准备将要被聚合的函数
        var JSON = {
            toJSONString :function(){
                var outPut = [];
                for(key in this){
                    outPut.push(key+" --> "+this[key])
                }
                return outPut;
            }
        };
        /**
         * 聚合函数
         */
        function mixin(receivingClass,givingClass){
            for(methodName in givingClass){
                if(!receivingClass.__proto__[methodName]){ //通过中括号访问json
                    receivingClass.__proto__[methodName] = givingClass[methodName]
                }
            }
        }
        var o = {name:"YUN",age:27}
        mixin(o,JSON);
        document.write(o.toJSONString().join(","))
    
    //-------------------------------------------------------------------
        JSON.prototype = {
            toJSONString :function(){
                var outPut = [];
                for(key in this){
                    outPut.push(key+" --> "+this[key])
                }
                return outPut;
            }
        }
        //制作聚合函数
        function mixin(receivingClass,givingClass){
            for(methodName in givingClass.prototype){
                //本类中没有这个函数的情况下我在聚合,否则跳过
                if(!receivingClass.prototype[methodName]){
                //传递的是地址
                    receivingClass.prototype[methodName] = givingClass.prototype[methodName]
                }
            }
        }
    
    //----------------------------------------------------------
        //var o = {name:"YUN",age:27}
        var o = function(){
            this.name = "YUN";
            this.age = 17
        }
        mixin(o,JSON);
        var a = new o();
        document.write(a.toJSONString().join(","))
    })()
  • 相关阅读:
    赞赏出版模式:在大众之中寻找大家,在凡品之上打造精品-百道网
    赞赏——人人都能赞赏成书
    赞赏网---赞赏网
    知乎利用众筹模式出书 颠覆传统出版业规则|众筹模式|出书|知乎_新浪新闻
    发起项目
    北京墨知缘文化传媒有限公司,出书,出书挂名, 代理出书,学术出书,出书流程,出书渠道,如何出书,出版,出版图书,想出书,怎么出书,出书费用,出书哪家好,那家出书最便宜,图书出版,书号申请,墨之源,墨知源,墨之缘
    springboot~openfeign从JSON文件读取数据
    springboot~openfeign从此和httpClient说再见
    java~mac下的终端工具oh-my-zsh
    springboot~内嵌redis的使用
  • 原文地址:https://www.cnblogs.com/yaowen/p/6889738.html
Copyright © 2011-2022 走看看