Question d’entretien chez LinkedIn

// What does this code return? var Foo = function (a) { this.bar = () => { return a; } var baz = function () { return a; }; }; Foo.prototype = { biz: () => { return this.bar(); } }; var f = new Foo(7); f.bar(); //=> f.baz(); //=> f.biz(); //=>

Réponses aux questions d'entretien

Utilisateur anonyme

27 mars 2019

f.bar(); //7 f.baz(); //baz is not defined error f.biz(); //undefined as this refers to window because of arrow function.

4

Utilisateur anonyme

15 juin 2022

var Foo = function( a ) { this.a = a; this.bar = function() { return this.a; } this.baz = function() { return this.a; }; }; Foo.prototype = { biz: function() { return this.a; } }; var f = new Foo( 7 ); console.log(f.bar()); console.log(f.baz()); console.log(f.biz());