LoginSignup
0
0

More than 5 years have passed since last update.

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

Posted at

問題

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

var obj2 = {
            x:4,
            doit2:fn
           }
obj2.doit2(); //=> ?

: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); }
          }
var fn = obj.doit;

var obj2 = {
            x:4,
            doit2:fn
           }
obj2.doit2(); //=> method is called.4
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