Skip to content

Instantly share code, notes, and snippets.

@tagawa
Forked from GarrettS/usurp-tco.js
Created January 30, 2012 06:26
Show Gist options
  • Save tagawa/1702902 to your computer and use it in GitHub Desktop.
Save tagawa/1702902 to your computer and use it in GitHub Desktop.
UsurpTCO
(function() {
if (window.location.hostname === "twitter.com") {
var tcoToLinkTitleURL = function(ev) {
var target = ev.target, dataURI = target.getAttribute("data-expanded-url");
if (/^https?:\/\/t.co\//.test(target.href) && dataURI) target.href = dataURI;
};
document.addEventListener("mousedown", tcoToLinkTitleURL, true);
}
})();
@GarrettS
Copy link

GarrettS commented Feb 1, 2012

Because FunctionDeclaration may not appear where only Statements are allowed, it is best to not do that. Who knows what future versions of Opera will do WRT newer recommendations from TG39 in Harmony or ES6. And then you have to scramble to update the (avoidable) bugs you coded in as a result of programming by observation.

One option is to use an anonymous FunctionExpression as .addEventListener("mousedown", function(){}, true);.

@GarrettS
Copy link

GarrettS commented Feb 1, 2012

A classic example of using FunctionExpression in programming is Google and GMail source, in particular. GMail guys wrote their code, then had a bunch of errors, so decided to wrap everything -- including FunctionDeclaration in try / catch -- a classic beginner folly.

And so when they did that, they created invalid syntax that worked in the browsers that they thought they were sniffing (browser sniffing is another folly that google has been employing for years). And the funny thing is that when Google wanted to make Closure Compiler (unreliable), is that they got in the predicament of trying to accommodate the invalid syntax that they'd been advised not to use, namely, they had to address the invalid use of FunctionDeclaration where only Statement may appear. And the problem with trying to accommodate that invalid syntax is that the behavior of such syntax depends on the implementation. So then they had to try and figure out what was wanted in the code, which of course was impossible to do globally because the desired interpretation was based on purely coincidence of "we did this and then it passed QA". And Google history shows a lot of bugs making it through QA (leading Richard Cornford to question the fact of even if Google does QA. Here's one of Richard's quotes:

Do Google have a QA department? My impression was that they just published their stuff untested and waited for complaints form the users.

What this really boils down to is that programming by is unreliable and not forwards compatible.

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