Quantcast
Channel: Posts/rss
Viewing all articles
Browse latest Browse all 38

Comment from Peter Bex

$
0
0
Private variables are useful in one other situation: When you're extending existing functions to do something additional. Example:

function somefunc() { ... };

(function() {
  var old = somefunc;
  somefunc = function() {
    alert('before somefunc');
    old.apply(this, arguments);
    alert('after somefunc');
})();
This prevents global namespace pollution with all kinds of 'old' function aliases.

Viewing all articles
Browse latest Browse all 38

Trending Articles