I'm trying to get the following code to work.
Array.prototype.test = {
func: function() {
console.log(this);
return this;
}
};
Then when I run the following.
[].test.func();
The problem is the this
within that function is the object Array.prototype.test
NOT the array that I passed in.
I feel like there has to be way to do this without setting Array.prototype.test
to a function and having to call it like so [].test().func();
.
Chai uses this type of syntax quite a bit. So I'm assuming it's possible.
How can I get this to work as I'm expecting it to?