Extend Math with custom prototypes in Ionic 2


#1

Hi,
I want to extend Math with new custom prototypes e.g. lerp and clamp.
For example Math.prototype.lerp = function(…) {…}.
But Ionic and typescript has to know this new methods. When typing in editor (vs code) these new methods must not be recognized as an error.

What’s the best way to do this?


#2

The ability to extend prototypes of standard language features is one of my least favorite “features” of JavaScript. Why can’t you just have these be ordinary utility functions?


#3

Ok, does Ionic have utilities like lerp and clamp to import? (otherwise I have to write my own)
Like:
import { lerp } from 'util/util';
or
import { util } from 'util/util';
… util.lerp(…)


#4

Not that I know of, but you can just copy some other implementation into:

Yes, I like that much better than polluting the standard Math.