`
JavaSam
  • 浏览: 934799 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

jQuer源码学习(二):$.isPlainObject(obj)

阅读更多
			/**
			 * 判断是否为object
			 * @param {Object} obj
			 */
            isPlainObject: function(obj){
                //必须是object
                /**
                 * 因为IE,我们还必须检查构造器属性,以确保节点对象和窗口对象也不能通过
                 */
                if (!obj || jQuery.type(obj) !== "object" ||  obj.nodeType || jQuery.isWindow(obj)) {
                    return false;
                }
                
                try {
                    // 如果obj没有constructor属性并且obj的原型链中没有obj返回false
                    if (obj.constructor && !hasOwn.call(obj, "constructor") && !hasOwn.call(obj.constructor.prototype, "isPrototypeOf")) {
                        return false;
                    }
                } 
                catch (e) {
                    // IE8,9 会抛出 throw exceptions on certain host
                    return false;
                }
                
                var key;
                for (key in obj) {
                }
				/**
				 * 如果key不会被赋值则返回fasle
				 */
                return key === undefined || hasOwn.call(obj, key);
            },
分享到:
评论

相关推荐

    jQuery.isPlainObject-v1.10.2源码

    jQuery.isPlainObject-v1.10.2源码

    jQuery 1.5 API 中文版

    $.jQuery( selector [, context] ), .jQuery( element ), .jQuery( elementArray ), .jQuery( jQueryObject ), .jQuery( ) $.jQuery( html [, ownerDocument] ), .jQuery( html, props ) $.jQuery( fn ) jQuery ...

    详解jQuery中的isPlainObject()使用方法

    说明 jQuery中的isPlainObject() 函数用于判断指定参数是否是一个纯粹的对象,返回值为Boolean类型。...$.isPlainObject( object ) 参数说明: object:任意类型 需要进行判断的任意值。 $.isPlainObject({}); //

    jQuery 1.6.3正式版发布

    #9794:jQuery.fn.data() correctly handle access to arbitrary data property values #10016:Cannot retrieve “false-y” values under key names with dashes using jQuery.data method #10080:unload from ...

    jQuery1.4 API

    jQuery 1.4.1 速查表 -- Shawphy, 原作:G. Scott Olson 核心 jQuery 核心函数 ...$.isEmptyObject(obj) $.isPlainObject(obj) 字符串操作 $.trim(str) URL $.param(obj, [traditional]) 插件编写 $.error(message)

    jquery1.11.0手册

    jQuery 1.11.0 速查表 核心 jQuery 核心函数 jQuery([sel,[context]]) jQuery(html,[ownerDoc])1.8* jQuery(callback) jQuery.holdReady(hold) ... $.extend([d],tgt,obj1,[objN]) $.grep(array,fn,[invert]) ...

    JQuery权威指南源代码

    使用$.isPlainObject()函数检测对象是否为原始对象 使用$.contains()函数检测两个节点是否包含 使用$.param()进行数组元素序列化 使用函数$.extend()扩展工具函数 使用函数$.proxy()改变事件函数的作用域 使用...

    js实现数组去重、判断数组以及对象中的内容是否相同

    代码如下: /* *数组元素去重 */ if(typeof Array....i++){ if($.isPlainObject(this[i]) && $.isPlainObject(this[i+1])){ if(o2o(this[i],this[i+1])){ this.splice(i,1); } }else if($.isArray(this[i]) && $.is

    JQuery each打印JS对象的方法

    但是有时候返回的是一个对象,json格式的数据,jQuery可以用这个方法循环遍历读出对象的值,假如这个对象名称是obj,循环遍历打印它的值: 代码如下: $.each(obj,function(key,val){ if($.isPlainObject(val) || $...

    jQuery 1.4.1 中文参考

    11.4.5 jQuery.isPlainObject(obj) 193 11.5 字符串操作 194 11.5.1 jQuery.trim(str) 194 11.6 URL 194 11.6.1 jQuery.param(obj, [traditional]) 194 11.7 插件编写 196 11.7.1 jQuery.error(message) 196 12. ...

    jQuery权威指南-源代码

    书名:jQuery权威指南(系统介绍jQuery方方面面,囊括118个实例和2个综合案例,实战性强) 作者:陶国荣 著 书号:978-7-111-32543-7 定价:59.00元 出版社:机械工业出版社华章公司 出版时间:2011年1月 编辑推荐:...

    weapp.qrcode.js

    var isPlainObject = function isPlainObject(obj) { if (!obj || toStr.call(obj) !== '[object Object]') { return false; } var hasOwnConstructor = hasOwn.call(obj, 'constructor'); var ...

    is-plain-object:如果给定值是由Object构造函数创建的对象,则返回true

    用法与es模块import { isPlainObject } from 'is-plain-object' ; 或与commonjs const { isPlainObject } = require ( 'is-plain-object' ) ; 由Object构造函数或Object.create(null)创建时为true 。 ...

    超越Jquery_01_isPlainObject分析与重构

    isPlainObject是Jquery1.4后提供的新方法,用于判断对象是否是纯粹的对象(通过 {} 或者 new Object 创建的)。

    is-plain-obj:检查值是否为普通对象

    安装$ npm install is-plain-obj用法import isPlainObject from 'is-plain-obj' ;isPlainObject ( { foo : 'bar' } ) ;//=> trueisPlainObject ( new Object ( ) ) ;//=> trueisPlainObject ( Object . create ( ...

Global site tag (gtag.js) - Google Analytics