JavaScript

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

More than 1 year has passed since last update.

問題

function Car(brand) {
   this.brand = brand;
}
Car.prototype.getBrand = function() {
   return this.brand;
}
var foo = new Car("toyota");
println(foo.getBrand());  // "toyota"
var brand = "not a car";
var bar = foo.getBrand;
println(bar());  // ?

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

function Car(brand) {
   this.brand = brand;
}
Car.prototype.getBrand = function() {
   return this.brand;
}
var foo = new Car("toyota");
println(foo.getBrand());  // "toyota"
var brand = "not a car";
var bar = foo.getBrand;
println(bar());  // "not a car"