What is the difference between the built-in `instanceof` Javascript operator and the` instanceOf` MooTools function?

MooTools has its own function instanceOf(instance, Type) .
I can only assume that it SOMETHING differs from the Javascript native instanceof , but I cannot understand that.

Can someone explain the difference or purpose of the instanceOf() function?

+4
source share
2 answers

instanceOf is free for typeOf , which are internal functions of MooTools that perform type traversal better than their native counterparts.

typeOf is a little more useful in this:

 typeof []; // object typeOf([]); // array typeof new Date(); // object typeOf(new Date()); // date 

instanceOf is mainly used for the class, although it also works for type constructors.

eg.

 var foo = new Class(), bar = new Class({ Extends: foo }); var foobar = new bar(); instanceOf(foobar, bar); // true // but also due to Extends prototype chain and the constructor: instanceOf(foobar, foo); // true // as well as standard behaviour like instanceOf([], Array); // true instanceOf(4, Number); // true vs 4 instanceof Number == false 

see source: https://github.com/mootools/mootools-core/blob/master/Source/Core/Core.js#L47-58

you may notice that many type constructors in mootools decorate objects to facilitate duck typing, so typeOf and instanceOf work with actual meaningful results.

also read a function like mootools

+3
source

At least:

 > "" instanceof String false > instanceOf("", String) true 
+2
source

Source: https://habr.com/ru/post/1435578/


All Articles