phaser源码解析(三) Phaser.Utils类下isPlainObject方法

/**
    * #这是一个对jQuery.isPlainObject(obj)稍加修改的方法。    一个 普通对象  obj.toString() => "[object Object]"                      
    * This is a slightly modified version of jQuery.isPlainObject. A plain object is an object whose internal class property is [object Object].
    * @method Phaser.Utils.isPlainObject     
    * @param {object} obj - The object to inspect.  ——#等待检查的对象 
    * @return {boolean} - true if the object is plain, otherwise false. ——#ture代表是一个普通对象, 否则返回false
    */
    isPlainObject: function (obj) {

        // Not plain objects: 不是 普通对象 包括:
        //#任何对象和值内置property属性的值不是[object Object]
        // - Any object or value whose internal [[Class]] property is not "[object Object]"  
        // - DOM nodes       ——#Dom对象
        // - window         ——#window对象
        if (typeof(obj) !== "object" || obj.nodeType || obj === obj.window)
        {
            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|
        // #判断obj是否具有isPrototypeOf属性,isPrototypeOf是挂在Object.prototype上的。通过字面量或自定义类(构造器)创建的对象都会继承该属性方法.
     //解释引子:http://www.cnblogs.com/phpmix/articles/1733599.html
        try {
            if (obj.constructor && !hasOwn.call(obj.constructor.prototype, "isPrototypeOf"))
            {
                return false;
            }
        } catch (e) {
            return false;
        }

        //#如果通过了以上的验证
        // If the function hasn't returned already, we're confident that
        // #我们就可以认为参数obj是一个普通对象,通过{}和new创建的对象
        // |obj| is a plain object, created by {} or constructed with new Object
        return true;
    }
原文地址:https://www.cnblogs.com/DhyDream/p/3593457.html