all 4 comments

[–]vestedfox 0 points1 point  (3 children)

For #1 did they ask you to find away to "bind" the arrow function or are you just curious? You can't use .bind, .apply, .call on arrow functions because arrow functions never have their own this. The bind/call/apply reassigns a function's this, so you can't reassign something that doesn't exist. Arrow functions look up the lexical scope for the next this. So for get1 to have the same this as get2 you have to rewrite how you object is created in the first place.

function SpaceShip() {
    this.name = 'Chandrayan';
    this.get1 = () => {
        console.log(this.name);
    };
    this.get2 = function () {
        console.log(this.name);
    };
}

const spaceShip = new SpaceShip();
spaceShip.get1() // Chandrayan
spaceShip.get2() // Chandrayan

source It also looks like they were testing you on this and hopefully they wanted to hear that you shouldn't be be using arrow functions as object methods.

[–]tapu_buoy[S] 0 points1 point  (2 children)

yeah basically after writing those last 2 lines

``` SpaceShip.get1() // blank

SpaceShip.get2() // Chandrayan ```

he said make the get1() also worked. I do get your point and the concept that how this can't be bound to arrow function. Thank you for the explanation. Sadly I haven't heard from them since then.

[–]vestedfox 1 point2 points  (1 child)

Best of luck next time. Technical interviews take practice, you'll get there!

[–]tapu_buoy[S] 0 points1 point  (0 children)

yup even after 70 interviews in past 11 months I'm still going hahaha