protoType and protoType Chain
there is simple question how can you check if a variable is an Array。
the answer is easy
1 | arr instanceof Array |
if result is true ,arr is Array .otherwise arr isn’t;
so there is another question: what’s principle behind instanceof in Javascript
let me explain
there’re two classes. People and Student . Student implements People
1 | class People{ |
1 | const huck = new Student('huck',100); |
“huck” is an instance of Student;
Here are the 3 basic rules in Prototype
“Every class in Javascript has a explicit prototype property”
“Every instance in Javascript has implicit prototype, proto“
“An instance’s proto prototype points to corresponding class”
take the value “huck” for example
huck has a __proto__
points to Student’s prototype.
and Student‘s __proto__
points to People’s prototype.
and People‘s __proto__
points to Object’s prototype.
Object‘s __proto__
points to null