Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (29 sloc) 1.29 KB
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* Title: (Not) Augmenting Built-in Prototypes
* Description: it can seriously hurt maintainability, because it will make your code less predictable
*/
/* NOTE: You can make an exception of the rule only when all these conditions are met:
* 1. It's expected that future ECMAScript versions or JavaScript implementations will implement this functionality
* as a built-in method consistently. For example, you can add methods described in ECMAScript 5 while waiting for
* the browsers to catch up. In this case you’re just defining the useful methods ahead of time.
* 2. You check if your custom property or method doesn't exist already—maybe already implemented somewhere else in
* the code or already part of the JavaScript engine of one of the browsers you support.
* 3. You clearly document and communicate the change with the team.
*/
if (typeof Object.prototype.myMethod !== "function") {
Object.prototype.myMethod = function () {
// implementation...
};
}
// References
// http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/
</script>
</body>
</html>