LoginSignup
0
2

More than 5 years have passed since last update.

[クイズ]javascriptと仲良くなるための一歩 第42話「this参照1」

Last updated at Posted at 2017-08-27

問題

var obj = {
           x:3,
           doit: function(){ console.log("method is called." + this.x); }
          }
obj.doit(); //=> method is called.3

var fn = obj.doit;
var x = 5;
fn(); //=> ?

: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 = {
           x:3,
           doit: function(){ console.log("method is called." + this.x); }
          }
obj.doit(); //=> method is called.3

var fn = obj.doit;
var x = 5;
fn(); //=> method is called.5
0
2
2

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
2