LoginSignup
0
0

More than 5 years have passed since last update.

[クイズ]javascriptと仲良くなるための一歩 第28話「nullでcreate1」

Posted at

問題

var obj = {}
Object.getPrototypeOf(obj); //=> Object {__defineGetter__: function, ~省略~}
'toString' in obj;          //=> true

var obj = Object.create(null);
Object.getPrototypeOf(obj); //=> ?
'toString' in obj;          //=> ?

: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:

答え

var obj = {}
Object.getPrototypeOf(obj); //=> Object {__defineGetter__: function, ~省略~}
'toString' in obj;          //=> true

var obj = Object.create(null);
Object.getPrototypeOf(obj); //=> null
'toString' in obj;          //=> false

creteで{}作りたいなら、

var obj = Object.create(Object.prototype);
Object.getPrototypeOf(obj); //=> Object {__defineGetter__: function, ~省略~}
'toString' in obj;          //=> true
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0