Spyke
Sad state of programming in my office

Sad state of programming in my office

We were trying to fix this problem for a project: "In JavaScript, how do we polyfill a fucntion that does not have the Function.prototype.call.

And then I saw my colleague do this Object.prototype.fn = something

And my colleagues are all supporting him saying "it works"

I said during the discussion, that Object.prototype is contaminated so this is not the right way.

The reply: Every object has its own Object.prototype so they don't affect the other.

What is the status of corsets these days?

First, this was supposed to do this for a Function, but he is accessing the Object instead, clearly he does not know what is to be done.
Secondly, all objects have a prototype link that points to the same Object.prototype object. I am seriously doubting he understands what the Object.prototype object is. Third, so many of my colleagues supporting him makes this whole situation even more sad.

What kind of graduates are our colleges making these days?

12
View all comments

Object.prototype.fn = something is object contamination. However, functions are Objects too (Function implements Object), so you can access it via Function.prototype.fn. It's recommended to use Function.prototype.fn = something instead for a better polyfill. Maybe you are looking for a solution similar to what's in this medium article?

As for the reply you received, you can easily write a code that proves its object contamination.

Object.prototype.fn = () => 42;
function gy() { return 24; }
gy.fn() // returns 42
a = { key: "value" }
a.fn() // returns 42, unexpected.

Maybe the team didn't understand what you wanted to share. Just try your best to put your point forward and explain it to them, it will help you and the team.

2