[Greasemonkey] GM presentation

Mark Pilgrim pilgrim at gmail.com
Fri Aug 5 14:30:21 EDT 2005


On 8/5/05, Edward Lee <edilee at gmail.com> wrote:
> "Obvious JavaScript techniques don't work" -> Pitfall #3: named forms
> 
> It's not really a javascript issue, but a DOM issue, I believe. It's
> like the document.all support added to Firefox even though it's not a
> specification from the w3c. Yes, it does make scripts work across
> browsers, but it doesn't make it standard. XHTML is quite strict, and
> learning that could be useful for someone so that they don't get
> sloppy.

HTML is quite strict too; its reputation for looseness is an
implementation issue, not a specification issue, and 99% of the XHTML
on the web suffers from the same sloppy implementation.  But let's not
go there.  I can change the wording to say that "common JavaScript +
DOM techniques don't work."  People coming from a JavaScript
background *will* hit these pitfalls, and that's the main point I want
to get across.

> Other things that you point out like pitfall #1 (auto-eval strings)
> and pitfall #2 (event handlers) are probably for the better. Auto-eval
> strings failed in previous versions of greasemonkey because of the
> function wrapper preventing the global scope from getting polluted,
> and that's good incase there are sloppy scripts on the page taking up
> global namespace. Same thing for the event handlers because writing to
> the onclick will overwrite other eventlisteners, and addEventListener
> allows multiple events to trigger.

Yeah, but it's highly annoying and non-intuitive that this doesn't work:

var myNewLink = document.createElement('a');
myNewLink.onclick = func;

> So perhaps they are pitfalls, but you could also mention that it'll
> improve the quality of scripts.. maybe :p It's like writing programs
> in languages with different warning/error settings. Greasemonkey 1.5
> turned on the strict flag ;)

I like the analogy of the "strict" flag, since all compiled languages
and several interpreted ones (like Perl) already have a flag like
that.  (Even Python spits out DeprecationWarnings now.)

Thanks.

-- 
Cheers,
-Mark


More information about the Greasemonkey mailing list