Cynosure.X International LLC

: :

Add Comment | Related Links | TrackBack
Related Content

YouOS Programming Pitfall #1 - this object

Programming on YouOS is really the first time that I programmed in JavaScript. Well, I have written Greasemonkey scripts before, which is also JavaScript. But I'm not yet a JavaScript guru, so I can't differentiate between pure JavaScript vs. Greasemonkey vs. YouOS just yet.

One thing I noticed about programming JavaScript in YouOS is that the global/local scope is defined somewhat differently than scope in other languages. In other languages, such as Java or C++, global scope elements (methods and variables) can be referenced in the local scope without quantification, as long as the local scope elements doesn't overwrite global scope elements. In YouOS, local scope cannot reference global scope elements without quantification. Typically, the quantification is done with the keyword "this".
For example, if you have a method "foo" and a method "bar" in your program, in order to access the method bar in foo, you have to quantify it as below (note "this.bar ()"):

bar ()
{
return "hello";
}

foo ()
{
var v = this.bar ();
}

Think of "this" as a reference to this object. In this case, it's your YouOS program. If you do not quantify "bar" in "foo", "foo" will not find "bar", and your program will not run correctly.

I don't know how long I spent debugging my YouOS programs due to this rule, but I know spent a very long time. Knowing this pitfall, development and debugging are moving a lot quicker now.

I don't know if this pitfall applies to all JavaScripts or only YouOS JavaScripts. Feel free to chime in if you know.

Chieh Cheng
Sat, 18 Mar 2006 13:09:37 -0800

Add Comment | Related Links | TrackBack
Related Content

Did your message disappear? Read the Forums FAQ.

Add Comment

Spam Control | * indicates required field
Your Name: *
E-mail:
Remember Me!
Comment: *
File attachment is optional. Please do not attach a file to your submission unless it is relevent.
Attach File:
(20 MB Max)
Spam Protection: * Answer of 2 + 0?
Click button only once, please!

TrackBack

TrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites.

Send Ping | TrackBack URL | Spam Control

No TrackBacks yet. TrackBack can be used to link this thread to your weblog, or link your weblog to this thread. In addition, TrackBack can be used as a form of remote commenting. Rather than posting the comment directly on this thread, you can posts it on your own weblog. Then have your weblog sends a TrackBack ping to the TrackBack URL, so that your post would show up here.

Messages, files, and images copyright by respective owners.

Products | Services
Forums | Latest | RSS
Library | Search | Wiki
Help | Licenses

Login | Register

43 Users Online

Hacking Digital Cameras
Fun for Photographers



Amazon Associate

Copyright © 1996 - 2023. All Rights Reserved.