zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    CUDA Error
    yolo v3 loss=nan, Avg loss=nan的一种原因
    C++ LinearRegression代码实现
    C++ 常用数学运算(加减乘除)代码实现 Utils.h, Utils.cpp(有疑问欢迎留言)
    C++ 彩色图像(RGB)三通道直方图计算和绘制,图像逆时针旋转90° 实现代码
    Leetcode 1005. Maximize Sum Of Array After K Negations
    Leetcode 1006. Clumsy Factorial
    Leetcode 617. Merge Two Binary Trees
    Leetcode 477. Total Hamming Distance
    python进制转换
  • 原文地址:https://www.cnblogs.com/DhyDream/p/3593457.html
Copyright © 2011-2022 走看看