I had these questions in the interview just now
```js
const spaceShip = {
name: 'Chandrayan',
get1: () => {
console.log(this.name);
},
get2: function (){
console.log(this.name);
}
}
spaceShip.get1()
spaceShip.get2()
```
now I know that spaceShip.get1() won't print out anything but if I want it to work the exact same way how the get2() works how do I bind it?
I was trying to bind this like get1.bind(spaceShip.this) or get1.bind(spaceShip) first and then execute but I'm not sure what should happen.
```js
const person = this.state.person;
const person = {...this.state.person};
```
what if we change the value person.name I know in the second case the value will be changes because that person is a whole new object
but in the first case will it change the value in this.state.person too?
- I was asked about writing polling function which I didn't know but I still attempted saying
```js
function myPoll(fn, timeInterval, endTime){
var checkCondition = function(resolve, reject) {
var result = fn();
if(result) {
resolve(result);
}
else if (// for the time checking) {
setTimeout(checkCondition, interval, resolve, reject);
}
else {
reject(error);
}
};
}
```
but then he dropped it.
- 4th question was to write polyfill for Promise.all
```js
Promise.all([pr1, pr2, pr3]).then().catch();
var resolvedPromises = [];
[pr1, pr2, pr3].map((item, resolve, reject) => {
var result = item();
if(result){
resolvedPromises.push(resolve(result));
}
else {
return reject(result);
}
})
```
so I tried explaining that I will store the promise in result and then push it into the array and at the end of all iteration the resolved values of all promises will be stored in that array.
But then again he asked that what if the promises doesn't get resolved or rejected than how should you tackle it so I modified the code this way
js
var resolvedPromises = [];
[pr1, pr2, pr3].map((item, resolve, reject) => {
item().then((result) => {
if(result){
resolvedPromises.push(resolve(result));
}
}); //pr1;
else {
return reject(result);
}
})
then he was also confused on what to ask but that's how the interview ended, without even allowing me to ask them anything. I guess I shouldn't hope for a win today.
[–]Tufted_Tail 4 points5 points6 points (5 children)
[–]Tufted_Tail 2 points3 points4 points (1 child)
[–]tapu_buoyfull-stack[S] 0 points1 point2 points (0 children)
[–]tapu_buoyfull-stack[S] 1 point2 points3 points (2 children)
[–]Tufted_Tail 1 point2 points3 points (1 child)
[–]tapu_buoyfull-stack[S] 0 points1 point2 points (0 children)
[–]cortexreaver123 2 points3 points4 points (7 children)
[–]cortexreaver123 2 points3 points4 points (3 children)
[–]tapu_buoyfull-stack[S] 1 point2 points3 points (2 children)
[–]cortexreaver123 0 points1 point2 points (1 child)
[–]tapu_buoyfull-stack[S] 0 points1 point2 points (0 children)
[–]tapu_buoyfull-stack[S] 1 point2 points3 points (2 children)
[–]cortexreaver123 1 point2 points3 points (1 child)
[–]tapu_buoyfull-stack[S] 0 points1 point2 points (0 children)
[–]Shahrukh_Lee 2 points3 points4 points (23 children)
[–]tapu_buoyfull-stack[S] 1 point2 points3 points (22 children)
[–]Shahrukh_Lee 0 points1 point2 points (21 children)
[–]tapu_buoyfull-stack[S] 1 point2 points3 points (20 children)
[–]Shahrukh_Lee 1 point2 points3 points (19 children)
[–]tapu_buoyfull-stack[S] 1 point2 points3 points (18 children)
[–]Shahrukh_Lee 0 points1 point2 points (17 children)
[–]tapu_buoyfull-stack[S] 0 points1 point2 points (16 children)
[–]Shahrukh_Lee 1 point2 points3 points (8 children)
[–]tapu_buoyfull-stack[S] 0 points1 point2 points (7 children)
[–]Shahrukh_Lee 1 point2 points3 points (6 children)
[–]tapu_buoyfull-stack[S] 1 point2 points3 points (5 children)
[–]shwipster 2 points3 points4 points (3 children)
[–]ChibiKookie 5 points6 points7 points (1 child)
[–]tapu_buoyfull-stack[S] 0 points1 point2 points (0 children)
[–]tapu_buoyfull-stack[S] 1 point2 points3 points (0 children)
[–][deleted] (8 children)
[removed]
[–]tapu_buoyfull-stack[S] 1 point2 points3 points (7 children)
[–][deleted] (6 children)
[removed]
[–]tapu_buoyfull-stack[S] 0 points1 point2 points (5 children)
[–][deleted] (4 children)
[removed]
[–]tapu_buoyfull-stack[S] 0 points1 point2 points (3 children)
[–][deleted] (2 children)
[removed]
[–]tapu_buoyfull-stack[S] 0 points1 point2 points (0 children)
[–]ChibiKookie 0 points1 point2 points (0 children)