Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Created May 4, 2010 20:33
Show Gist options
  • Select an option

  • Save rwaldron/389933 to your computer and use it in GitHub Desktop.

Select an option

Save rwaldron/389933 to your computer and use it in GitHub Desktop.
(function ($) {
$.fn.pollute = function (pollution) {
// first we extend the pollution object to the window, nice!
$.extend(window, pollution);
// make sure we're really nasty, and pollute all the elements as well.
return this.each(function () {
for ( var junk in pollution ) {
if ( typeof pollution[junk] === 'object' ) {
$(this).pollute(pollution[junk]);
return;
}
$.extend(this, pollution);
}
});
}
})(jQuery);
//Usage
$(document).pollute({
foo: 'bar',
more: {
crap: 'baz',
yuck: 'junk'
},
badass: window
});
// Automatically adds foo to the global scope!
// As an added bonus the junk gets put on EVERY MATCHED ELEMENT in the collection as well!
// Yippee!!
@rwaldron

rwaldron commented May 4, 2010

Copy link
Copy Markdown
Author

The goal here is to make it WAY easier for crappy javascript "programmers" to just pollute the hell out of the global window scope. I mean, really, why waste time defining functions and vars individually when you can just barf them all out in one go! It's like extending, but for everything at once! AWESOME!

@bnvk

bnvk commented May 4, 2010

Copy link
Copy Markdown

Hehe. This is a funny thread and plugin!

@rwaldron

rwaldron commented May 4, 2010

Copy link
Copy Markdown
Author

@brennannovak - I want my work to be taken seriously. This is a real problem. I dont want to have to waste my time with namespaces - thats just too hard to remember!!

@bnvk

bnvk commented May 4, 2010

Copy link
Copy Markdown

Hehe, mesa-thinks it's funny that it's called "pollution" :)

@paulirish

Copy link
Copy Markdown

Dig the circ-referencing memory leakage that's seeping out, too.

@rwaldron

rwaldron commented May 4, 2010

Copy link
Copy Markdown
Author

@paulirish - It's very feature rich like that! I wanted to make sure I covered all the important aspects of REAL javascript programming.

@enguyen

enguyen commented May 4, 2010

Copy link
Copy Markdown

I think I just saw Douglas Crockford leaving this page, clutching his stomach and puking.

@rwaldron

rwaldron commented May 4, 2010

Copy link
Copy Markdown
Author

That's ok, because I tried to read his book and it was too confusing. All this non-sense about scope and closures?? WTF OMFG!!

@arxpoetica

Copy link
Copy Markdown

lol!

@arxpoetica

Copy link
Copy Markdown

@brennannovak i just realized you jar-jar-jinxed this

@jacobandresen

Copy link
Copy Markdown

heeehe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment