Question points and advice of isPlainObject function in jQuery source code

Code:

//  {}new Object()Object.create(null)
    isPlainObject: function( obj ) {
        var proto, Ctor;

        // toStringobjObject
        if ( !obj || toString.call( obj ) !== "[object Object]" ) {
            return false;
        }
        // 
        proto = getProto( obj );

        // Object.create( null )true
        if ( !proto ) {
            return true;
        }

        // new Object()
        Ctor = hasOwn.call( proto, "constructor" ) && proto.constructor;
        // fnToString: ObjectFunctionString:function Object() { [native code] }
        return typeof Ctor === "function" && fnToString.call( Ctor ) === ObjectFunctionString;
    }

doubt:

Object.prototype.toString.call()new Object(){}Object()[object Object]
Mar.16,2021

Please indicate the version of jQuery. The details of the implementation code vary from version to version. In addition, the code you posted is the source code of jQuery. If so, please indicate it.


personal understanding is that toString.call is easier to write than Object.prototype.toString.call , because toString and Object.prototype.toString actually point to the same method:

clipboard.png

these two reasons for equality:
if you can use toString , then toString must be the method of window object, window is an object, and
all objects will eventually point to Object.prototype if they have prototypes.
if the window object or the prototype object other than the last prototype object does not redefine toString , then toString ultimately points to Object.prototype.toString ;
verified by the screenshot above, the two are indeed the same.

Menu