jQuery工具方法中的判断方法
来源:互联网 发布:linux时钟中断 编辑:程序博客网 时间:2024/06/06 02:44
对象自变量:
两种形式:|obj| is a plain object, created by {} or constructed with new Object
1. var obj = {};
2. var obj = new Object();
obj.constructor.prototype中有isPrototypeof ()方法,因为只有Object.prototype中有isPrototypeof ()方法。
isPlainObject: function( obj ) {// Not plain objects:// - Any object or value whose internal [[Class]] property is not "[object Object]"// - DOM nodes// - windowif ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {return false;}// Support: Firefox <20// The try/catch suppresses exceptions thrown when attempting to access// the "constructor" property of certain host objects, ie. |window.location|// https://bugzilla.mozilla.org/show_bug.cgi?id=814622try {if ( obj.constructor &&!core_hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {return false;}} catch ( e ) {return false;}// If the function hasn't returned already, we're confident that// |obj| is a plain object, created by {} or constructed with new Objectreturn true;},
var arr = [], obj1 = {}, obj2 = new Object();console.log($.isPlainObject(arr));//falseconsole.log($.isPlainObject(obj1));//trueconsole.log($.isPlainObject(obj2));//true
window的判断:
isWindow: function( obj ) {return obj != null && obj === obj.window;},
null 和undefined不能添加属性,否则会报错
var obj = null;obj.a=100;//Uncaught TypeError: Cannot set property 'a' of null
var obj = undefined;obj.a=100;//Uncaught TypeError: Cannot set property 'a' of undefinedwindow既可以是全局对象,也可是是全局对象下的窗口对象
console.log(window === window.window);//true
isFunction: function( obj ) {return jQuery.type(obj) === "function";},isArray: Array.isArray,isNumeric: function( obj ) { return !isNaN( parseFloat(obj) ) && isFinite( obj );},isEmptyObject: function( obj ) {var name;for ( name in obj ) {return false;}return true;},
阅读全文
0 0
- jQuery工具方法中的判断方法
- jQuery中的工具方法 $.xxx()
- jquery中的工具方法$.isFunction, $.isArray(), $.isWindow()
- jquery中的工具方法--Deferred和when
- jquery工具方法
- jquery工具方法
- jQuery工具方法
- jQuery工具方法
- jQuery工具方法
- Jquery--工具方法
- IE版本判断,jquery方法
- android 时间判断工具方法
- jQuery中的extend方法
- jQuery中的end()方法
- jquery 中的 attr()方法
- jQuery中的toggle方法
- Jquery中的each方法
- jQuery中的end()方法
- 让企业大数据具备抗灾能力的12种方法
- MongDB分页java实现
- caffe绘制训练过程的loss和accuracy曲线
- 博客迁移
- 通过目录处理函数实现文件浏览功能
- jQuery工具方法中的判断方法
- JSP的九大内置对象
- mysql主从配置
- php实例化类
- iTunes 12.7 没有应用程序选项了,还能好好地打包吗?
- webpack实战——(2)基本配置
- 注解实现AOP(获取输入及返回参数)
- web客户端 向 wcf rest服务端 上传文件
- php使用对象