zoukankan      html  css  js  c++  java
  • Js练习代码

    一、复制对象

    以下是代码:

    function copy(oldObj){
        var newObj=oldObj;
        if(isObject(oldObj)){
                newObj={};
        }
        if(isArray(oldObj)){
                newObj=[];
        }
        
        for(p in oldObj){
            var value=oldObj[p];
            if(isObject(value)||isArray(oldObj)){
                newObj[p]=copy(value);
            }else{
                newObj[p]=value;
            }
        }
        return newObj;
    }
    function isObject(obj){
        return Object.prototype.toString.call(obj) === "[object Object]";
    }
    function isArray(arr){
        return Object.prototype.toString.call(arr) === "[object Array]";
        
    }
    console.log(copy(1));
    console.log(copy('3a2'));
    console.log(copy(false));
    console.log(copy(function(){
    }));
    console.log(copy({c:1,d:2}));
    console.log(copy({c:1,d:{
            in1:1,
            in2:{
                a:'11111'
            }
        }
    }));
    console.log(copy([1,2,{a:[1,{a:[7,8,9]}],b:false,c:"3783",d:function (){
        var name="sam";
        this.infun =function (){
            console.log("hhh");
        };
        this.age=18;
    }}]));

    以下是结果

     二、对象curring

    function add(){
        var args=[].slice.call(arguments);
        
        var adder=function(){
            [].push.apply(args, [].slice.call(arguments));
            return adder;
        }
        adder.toString = function () {
            var sum=0;
            args.forEach(function(value){
                sum=sum+value;
            })
              return sum;
            }
        return adder;
    }
     console.log(add(1, 2, 3, 4, 5)); // 15 
     console.log(add(1, 2, 3, 4)(5)); // 15 
     console.log(add(1)(2)(3)(4)(5)); // 15

    柯里化就是参数部分使用。外部函数处理部分应用,剩下的由外部函数的返回函数处理。3个常见作用:1. 参数复用2. 提前返回;3. 延迟计算/运行

     三、v code设置外观

    {
        // 控制字体系列。
        "editor.fontFamily": "Source Code Pro, Menlo,Monaco",
        "editor.lineHeight": 24,
        "editor.renderLineHighlight": "none",
        "editor.roundedSelection": false,
        "editor.fontSize": 14,
        "extensions.autoUpdate": true,
        "editor.tabSize": 2,
        "files.associations": {
            "*.wxss": "css",
            "*.wxml": "html"
        },
        "extensions.ignoreRecommendations": false,
        "git.enableSmartCommit": true,
        "workbench.colorTheme": "Monokai"
    }
  • 相关阅读:
    ASP.NET中的Eval与DataBinder.Eval()方法
    数据库三范式
    某一公司的面试题目
    Gridview样式
    截取字符串代码
    C#文件IO操作
    随机生成验证码
    HTTP 错误 401.2 Unauthorized 由于身份验证头无效,您无权查看此页。 IIS7.0解决办法
    危险字符过滤的类
    asp.net面试题新手必备
  • 原文地址:https://www.cnblogs.com/jieru/p/7249280.html
Copyright © 2011-2022 走看看