JavaScript

[クイズ]javascriptと仲良くなるための一歩 第18話「instanceofで型判定」

More than 1 year has passed since last update.

問題

arr = [1,2,3]
arr instanceof Array //=> true

function A() {}
function B() {}
A.prototype = new B();

var a = new A();
a instanceof A      //=> ?
a instanceof B      //=> ?
a instanceof Object //=> ?

:mouse:
:cow:
:tiger:
:rabbit:
:dragon_face:
:snake:
:horse:
:sheep:
:monkey_face:
:bird:
:dog:
:boar:
:mouse:
:cow:
:tiger:
:rabbit:
:dragon_face:
:snake:
:horse:
:sheep:
:monkey_face:
:bird:
:dog:
:boar:

答え

arr = [1,2,3]
arr instanceof Array //=> true

function A() {}
function B() {}
A.prototype = new B();

var a = new A();
a instanceof A      //=> true
a instanceof B      //=> true
a instanceof Object //=> true