jquery源码—— 扩展工具方法

1、isWindow 判断的意义是什么?

2、isFunction 调用$.type 进行判断;

3、isNumeric 判断是否可转为数字类型 isNumeric(‘123’)true; isNumeric(123) true;isNumeric(NaN) false; 

type 判断是否为 number 和 string,如果是字符则进行运算判断是否为NaN,返回结果;

4、isPlainObject,官方解释是是否为一个‘纯粹的对象’,就是{},或者通过new Object()创建;关于‘不纯粹的对象’,个人猜想为null??(e.g., `Object.create( null )`); 验证 $.isPlainObject($('.test'))  返回值为false;

判断依据是—— 源码还没看明白呢...

5、isEmptyObject  是否是空对象;

6、type 判断数据类型 null undefined number string boolean function object array;

function type (obj) {
        if(obj === null){
            return null + '';
        }
        //  typeof obj  结果为object 的有 null, array,object;
        // if(typeof obj === 'object'){
        //     if(Object.prototype.toString.call(obj) == '[object Object]'){
        //         return 'object';
        //     }else{
        //         return 'array';
        //     }
        // }
        // return typeof obj;
        // 简写
        return typeof obj === 'object' ? (Object.prototype.toString.call(obj) === '[object Object]' ? 'object' : 'array') : typeof obj;
    }
// 源码
	type: function( obj ) {
		if ( obj == null ) {
			return obj + "";
		}

		// Support: Android <=2.3 only (functionish RegExp)
		return typeof obj === "object" || typeof obj === "function" ?
			class2type[ toString.call( obj ) ] || "object" :
			typeof obj;
	},

7、globalEval  == DOMEval ;

8、camelCase 驼峰式写法; $.camelCase('an-gela-lll') ----- anGelaLll;

9、each,两种写法 ----$.each(obj,callBack);  或者 $().each(callBack);  callBack 有两个参数,index 和 ele; 因为 $(this) 指向了 ele, 参数简写,index 放在前面;和forEach 有区别;

源码没有看懂,只知道怎么用;

10、trim 消除两端的空格,对字符进行操作;$.trim('    123eds   ');  

11、makeArray 两个参数 arr ,result ; 把 arr 变成数组 和result 进行合并; 如果arr 是数组 push到result中; 如果是字符数字function....,变成数组插入到result 中;最终的数据类型有result 决定;

12、inArray 是否在数组中;   参数ele,arr,index ele 是否存在在arr 内,从index 位开始查找; 利用indexof(ele,arr,index);

13、merge

14、grep 

15、map 带返回值

16、proxy

17、now 

18、support

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值