DEV Community

Discussion on: JS Polyfills asked in Interviews

jakewhelan profile image
Jake Whelan • Edited on

Sorry I do get your point and I would never ask for the dictionary definition of prototypical inheritance because as you suggest: it’s fruitless.

However if I asked you to remove the first argument because its redundant and you couldn’t I would have to assume your knowledge of prototypical inheritance is a WIP - and that might be fine, but it depends on seniority.

As for modifying global prototypes: that’s exactly what core-js does. For polyfills it’s standard.

The polyfill: (proto: true)

The documentation for proto arg:

prototype as the target for the “export”:

Thread Thread
marzelin profile image
Marc Ziel

If you don't know the proper names for programming concepts how will you be able to communicate efficiently with the rest of the team? And what are those better ways for testing? I hope it's not a random coding challenge because it isn't any better imho.

Thread Thread
lukeshiru profile image
LUKESHIRU • Edited on

Edit: This answer was supposed to go to this comment but for some reason it went to another one (I answered from the notifications on DEV).

Yup, maybe I wasn't clear and what I said got mixed up, but those are two different things:

  • You shouldn't ask for pollyfills in interviews, because in the real world we already have solutions for those (as core-js).
  • You can test for something like "adding something new to an existing prototype, but that's not something you should do in general, unless that prototype is completely under your control.

So to test all the things you mentioned in your previous comment (even if we nowadays we have classes in JS), you could simple give the candidate a piece of code like this:

function Example (initialCount = 0) {
  this.count = initialCount;

// ???

const example = new Example();

example.increment().count; // should be 1
example.increment(2).count; // should be 3
example.decrement(3).count; // should be 0
Enter fullscreen mode Exit fullscreen mode

And ask them to implement those increment and decrement methods. Why would you ask them to modify the prototype of a global like Array or Object when is a bad practice in the real world, or to implement a polyfill when that's done by packages like core-js? We should be interviewing for real world scenarios.

About this comment I was talking about terms like "hoisting", "asi" and stuff like that, which many folks are aware of but don't know the "actual name" for it, and it doesn't actually matter in the day-to-day work.