解读开源js函数的收获

JS活用

>

代码

var t, n, e, r, a;
for(t = {},
 a = "Boolean Number String Function Array Date RegExp Undefined Null".split(" "),
 n = a.length;
  n > r; r++)
    e = a[r],
    t["[object " + e + "]"] = e.toLowerCase();

StrObject.split(” “):分割字符串;“,”替换“指定字符串”;
StrObject.toLowerCase():字符串小写 ;
“,” “||” “&&” 三种运算符的使用;
禁止选中

//js    弊端。只对该对象生效。外部仍会触发
                oncontextmenu="return false;" //禁止鼠标右键
                ondragstart="return false;" //禁止鼠标拖动
                onselectstart="return false;"//禁止选中文字
                onselect="document.selection.empty();"//禁止复制文本
//D3
                a
                .attr("onselectstart",function () {
                    return "return false";
                })
                .attr("onmousedown", function () {
                    return "return false";
                })
                .attr("ondragstart",function () {
                    return "return false";
                })

深拷贝

        function getType(o) {
            var _t;
            return((_t = typeof(o)) == "object" ? o == null && "null" || Object.prototype.toString.call(o).slice(8, -1) : _t).toLowerCase();
        }```

     function extend(destination, source) {
            for(var p in source) {
                console.log(p);
                if(getType(source[p]) == "array" || getType(source[p]) == "object") {
                    destination[p] = getType(source[p]) == "array" ? [] : {};
                    arguments.callee(destination[p], source[p]);
                } else {
                    destination[p] = source[p];
                }
            }
        }

s

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值