Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

3 of 3
Commonmark migration

It's not recomended to extend Object.prototype, this will lead to strange behaviours and there is no need to do it one way if there is a less dangerous one like a simple function.

in_array(obj, [ 'a', 'b', 'c' ]);

You can even create a utils object

utils.in_array(obj, [ 'a', 'b', 'c' ]);

Once I've said that...

This looks very similar to Extending Object.prototype JavaScript and I totally agree with Alex Wayne:

I think it's fine if it works in your target environment.

Also I think prototype extension paranoia is overblown. As long as you use hasOwnProperty() like a good developer that it's all fine. Worst case, you overload that property elsewhere and lose the method. But that's your own fault if you do that.

AltStyle によって変換されたページ (->オリジナル) /