[Greasemonkey] Arrgghh!!! it runs asynch!!!

Tom Emerson osnut at pacbell.net
Wed Jun 28 22:46:58 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jeremy Dunck wrote:
> On 6/28/06, Tom Emerson <osnut at pacbell.net> wrote:
[first I do this]
>>         var refText = responseDetails.responseText;
[then]
>>         var newIMG = refText.match(/some extraction/g);
[and]
>>         var imgWidth = newIMG.match(/some sub-extraction/g);
>>
>> I get the error that "newIMG.match" is not a function.  ... the inconsistency drove me nuts
>> for quite some time)
> 
> The response is a string, which has a match method.  The match method
> is a convenience over RegExp.prototype.exec, which returns an array of
> groupings.  An array doesn't have a match method.  :)

this is why I asked for someone who knows what they are doing at the
outset -- silly of me not to realize that an untyped "var" is different
than another untyped "var" ;) </sarcasm>

Seriously, though, I had no idea that it was because the second item
(newIMG) was NOT a string -- how exactly would I have known that?
(remember, my background is COBOL, which /can/ be lenient in it's typing
of variables, and visual basic, which if you use "variants" will drive
you insane, hence I /almost/ always explicitly typecast any and all
variables I use)

> What behavior wouldn't have driven you nuts?

knowing more about variables & types within javascript.  The docs I was
reading to figure this out were giving me the impression that .match()
was returning a string, and since strings have .match() methods, I was
perplexed as to why the first string worked while the second string
failed.  Now I know better (and have less appreciation of the language
than I did before, which is pretty bad because before I knew anything
about the language, I obviously had nothing to appreciate...)




- --
Top o' the Blog: It's good to be the King...
http://osnut.homelinux.net/mtblog/ya_index.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEo1tCV/YHUqq2SwsRAguqAKCbP7CYyHqARXvtUnuFTmfCspKJTwCfcQtk
v7AT5JCVQ9A4xatqEuglaaA=
=x07X
-----END PGP SIGNATURE-----


More information about the Greasemonkey mailing list