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(","))
})()
复制代码


相关文章
|
1月前
|
数据可视化 JavaScript 前端开发
Turf.js介绍
Turf.js介绍
44 0
|
3月前
|
JavaScript 前端开发 Java
js常用技巧汇总
js常用技巧汇总
|
5月前
|
JavaScript
|
5月前
|
人工智能 JavaScript 前端开发
js的转变
js的转变
33 0
|
8月前
|
JSON JavaScript 前端开发
js常见题
js常见题
36 0
|
JavaScript
js有什么用
js有什么用
62 0
|
JSON 缓存 JavaScript
JS之12个小技巧
JS之12个小技巧
89 0
JS之12个小技巧
|
JavaScript 前端开发
sdmenu js
引用:http://hi.baidu.com/coolcat_police/blog/item/8762694446a8ed87b3b7dc06.html 其它博文:http://hi.baidu.com/coolcat_police/blog/category/Jquery     上网下载sdmenu的javascript。
893 0
|
前端开发 JavaScript
|
JavaScript 前端开发