Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (26 sloc) 855 Bytes
<!doctype html>
<html lang="en">
<title>JavaScript Patterns</title>
<meta charset="utf-8">
/* Title: Minimizing Globals
Description: they are declared outside of any function or simply used without being declared
myglobal = "hello"; // antipattern
console.log(myglobal); // "hello"
console.log(window.myglobal); // "hello"
console.log(window["myglobal"]); // "hello"
console.log(this.myglobal); // "hello"
// If you have to (gun to your head) use globals like jQuery does think of using a prefix and holding all your information in an object
prefix_myglobal = {
method: function () {},
property: "hello"
// References