javascript学习笔记

1、function 函数的bind方法:

Function.prototype._bind = function (context) {
    var fn = this;
    return function () {
        console.log('init constructor');
        fn.apply(context,arguments);
    }
}
var foo = {x:"foo "};
var baz = function (str) {
    console.log(this.x + (arguments.length === 0 ? '':str));
}
baz();
var _bind = baz._bind(foo);
_bind('baz');

call 方法 重写:

 Function.prototype._call = function (context,args) {
        var fn = this;
        console.log('init constructor');
        var self = context;
        fn.call(self,args);
    }
    var foo = {x:"foo "};
    var baz = function (str) {
        console.log(this.x + (arguments.length === 0 ? '':str));
    }
    baz();
    var _call = baz._call(foo,'barfd');
//    _call('barza');
    baz.call(foo,'barza');

2、正则表达式替换URL参数名:

3、javascript 静态方法的继承

function A() {
    console.log('test a');
    this.say = function () {
        console.log('aaaa');
    }
}
A.sayHello = function(){
    console.log('test a static method');
};
function B() {
    A.call(this);
    console.log('test b');
    this.sayB = function () {
        console.log('this is b say');
    }
}
B.sayHello = function () {
    A.sayHello();
}
B.sayHello();
var b = new B();
b.say();

4、移动适配viewport的指定

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

5、js 深copy

var obj = {a: 1, b: 2, c: {d: 3, f: 5}};
function deepClone(obj, source) {
    var result = source || {};
    for (var key in obj) {
        if (typeof obj[key] === 'object') {
            result[key] = obj[key].constructor === Array ? [] : {};
            deepClone(obj[key], result[key]);
        } else {
            result[key] = obj[key];
        }
    }
    return result;
}

var array = deepClone(obj);
console.log(obj);
console.log(array);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值