On the problem of judging js simple objects (plain object)

this is how redux is implemented https://github.com/reactjs/re.,
what puzzles me is the latter operation,

  let proto = obj
  while (Object.getPrototypeOf(proto) !== null) {
    proto = Object.getPrototypeOf(proto)
  }
  return Object.getPrototypeOf(obj) === proto*

personal rough opinion should be returned true anyway. What is the meaning of this operation?

ask the great god to answer questions and questions.

Mar.05,2021

let proto = obj / / proto default
while (Object.getprototypeOf (proto)! = = null) {/ / determine whether the prototype object of proto exists

proto = Object.getprototypeOf(proto) // protoproto,

}

return Object.getPrototypeOf (obj) = proto* / / actually determines how many layers the prototype chain of obj has, and only one layer returns true


find the top of the prototype chain


when it comes to the inheritance of the prototype chain, you can understand it by running the code:

function Foo() {}

// objplain object
var obj = new Foo();

console.log(typeof obj, obj !== null);


let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
  proto = Object.getPrototypeOf(proto)
}

// false
var isPlain = Object.getPrototypeOf(obj) === proto;
console.log(isPlain);

then the problem arises, according to the definition of the isPlainObject method on jQuery

isPlainObject: function( obj ) {
        var proto, Ctor;
        if ( !obj || toString.call( obj ) !== "[object Object]" ) {
            return false;
        }

        proto = getProto( obj );
        if ( !proto ) {
            return true;
        }
        Ctor = hasOwn.call( proto, "constructor" ) && proto.constructor;
        return typeof Ctor === "function" && fnToString.call( Ctor ) === ObjectFunctionString;
}
var o = Object.create(null) 

the object defined above uses $.isPlainObject to determine whether the result is true, which is the correct implementation according to redux's isPlainObject method to determine which result is false,.


Why not use Object.prototype.toString.call (obj)
to judge?


is to find the father
find null and then stop, and begin to compare the son of null with the father of the object of judgment.
object's father is the top object object, grandfather is null
father equals father
function father is function, grandfather is object, great grandfather is null
grandfather is not equal to father


find the top of the prototype chain

  https://www.zhihu.com/questio.

					
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3f487-414c1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3f487-414c1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?