287
288 //-- Define degrees function
289 if (typeof Number.prototype.toDeg === "undefined") {
290 Number.prototype.toDeg = function () {291 return this * (180 / Math.PI);292 };293 }
294
295 //-- Define middle point function
280
281 //-- Define radius function
282 if (typeof Number.prototype.toRad === "undefined") {
283 Number.prototype.toRad = function () {284 return (this * Math.PI) / 180;285 };286 }
287
288 //-- Define degrees function
In JavaScript, you can extend any object, including builtin or "native" objects. Sometimes people change the behavior of these native objects in ways that break the assumptions made about them in other parts of the code.
// seems harmless
Object.prototype.extra = 55;
// loop through some userIds
const users = {
"123": "Stan",
"456": "David"
};
// not what you'd expect
for (const id in users) {
console.log(id); // "123", "456", "extra"
}
In the above example, a common suggestion to avoid this problem would be to wrap the inside of the for
loop with users.hasOwnProperty(id)
.
Object.prototype.a = "a";
Object.defineProperty(Array.prototype, "times", { value: 999 });