Skip to content

Instantly share code, notes, and snippets.

@mlms13
Created September 26, 2014 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlms13/a469b4b4e0f9501d8fe1 to your computer and use it in GitHub Desktop.
Save mlms13/a469b4b4e0f9501d8fe1 to your computer and use it in GitHub Desktop.
Why type-checking (even in an environment like Phantom) is virtually impossible in Javascript
var foo = {
filter: function () {}
};
var bar = [];
// return filtered array or object
function filterer(baz) {
return baz.filter();
}
// call filterer with an object that has a `filter` function
filterer(foo);
// on some user interaction that wouldn't be executed by phantom,
// call `filterer` with a completely different type of argument
// that may or may not have a `filter` function
document.querySelector('#some-button').addEventListener('click', function () {
filterer(bar);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment