Q:

Why can't I assign `push` function to a variable?

Here's my first example which works as expected:

const testObj = {
   func: (str)=> { console.log(str) }
}

const testVar = testObj.func;

testVar("Working"); //logs "Working"

However if I try the same thing with a push function, it is undefined. 

const array = [];
const testVar = array.push;

console.log(testVar); // function push() { [native code]}

testVar("Should Be added"); // TypeError: undefined is not an object (evaluating 'testVar("Should Be added")')

Why is this?

A:

push needs to know what this will be when you call it so it know what it's pushing into — normally this will be the array you called it on. If you separate the function from the array you lose that binding because this is set by the way you call a function. You can explicitly put it back together using call():

const array = [];
const testVar = array.push;

testVar.call(array, "Should Be added"); 
console.log(array)

or bind()

const array = [];
const testVar = array.push.bind(array);

testVar("some value")
console.log(array)

