Javascript .watch() method.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Javascript .watch() method.

Post by JellyFish »

I'm having trouble getting this method to work. I tried testing it on an Untitled page in Firebug and it simple doesn't work.
  • Code: Select all

    obj = {prop: 0};
  • Code: Select all

    obj.watch("prop", function () {
    alert(this.prop);
    });
And so when I change the obj.prop's value the function doesn't run and there's no alert message. Whaaaa! :cry:

Am I messing something?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Try alerting a regular string like "working." It may be a problem with your use of this.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

superdezign wrote:Try alerting a regular string like "working." It may be a problem with your use of this.
Nah. That didn't work. Maybe it's a firebug bug?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

JellyFish wrote:Nah. That didn't work. Maybe it's a firebug bug?
That wouldn't make sense. That would imply that it worked in IE and not in FF.

I've never used the watch method before, so I doubt I'll be too much help on it... Simple alerts seem to work fine enough.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Yeah. Well I know that it should work. After all the watch method was described in MDC javascript documentation.

I just don't get it. This would be an awesome method to use to build a library. Don't you think?
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Hey I got it working. It just didn't work with firebug. I tested the code at http://htmledit.squarefree.com. Woot!

But it doesn't appear to work in IE. :( Damn you lazy, no good, son of a... MICROSOFT!
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Yes - firebug doesn't allow calls to alert() at all. Whenerver you call an alert() firebug throws an exception. I don't know why ...
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

Post by smudge »

@VladSun: I've noticed that too, but only in some cases. Sometimes I'll try to alert() something, and FB just sits there, but 5 min later, I try alert("Hello") and it alerts it.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

@smudge: I am not sure that firebug "fires this bug" ;) at every usage of alert. But having a 99% possibility of this happening, it is safer to turn off firebug when there are calls to alert().
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I am really not seeing this error at all. I've never run into a problem with my scripts and Firebug...
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Well, I've seen it too often. Maybe it depends on the software ... I am using:

Windows XP SP2
Mozilla/5.0 (Windows; U; Windows NT 5.1; bg; rv:1.8.1.5) Gecko/20070713 Firefox/2.0.0.5
FireBug 1.05

And it is for sure that calling alert() causes Firebug to throw an exception (maybe not every time) - I jsimply add/remove alert("OK") line and the results are different when usiing Firebug.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Alerts work fine in firebug for me. Except in this case.
Post Reply