PDA

View Full Version : Extending



JohnT
23 Oct 2006, 4:37 AM
I am excited. I really am enjoying Javascript, as I am fairly new at it.

So let's say I wanted to add a method:


el.saySomething

to your library. In this basic example it will attach an alert box that says hello world to the element when clicked.

Could someone show me where, and how to do this simple example. Also, what is the correct terminology for doing this? Is this extending a class?

Thanks!

John T.

jbowman
23 Oct 2006, 7:31 AM
I was where you are not that long ago :)

Best resource for learning how to extend things is Yahoo!s developer pages.

http://developer.yahoo.com/yui/yahoo/

That should help you a lot.

JohnT
23 Oct 2006, 7:39 AM
Terrific, I will sure have a look at that. Thank you.

jbowman
23 Oct 2006, 10:10 AM
I'd suggest going ahead and setting up a new namespace for your poject to store all that code in as well. I've found it works wonders for code maintenance and manageability.

JohnT
23 Oct 2006, 10:16 AM
Is there ANY way I can talk you into the showing me the simple alert example??? :)

BTW... I am on dev yahoo now reading.

Thanks!

Oh, I am also unsure about these NameSpaces. I know that this is a namespace:




YAHOO.example = function() {}



so are you suggesting I do something like this?




YAHOO.jbowman = function () {}



and do I have to use YAHOO? Could I use:




MISTER.jbowman = function () {}



Thanks for helping me!

John T.

samsmits
23 Oct 2006, 7:42 PM
Hi John,

Check out the screencasts by Dustin Diaz - I'm sure they'll familiarize you.

www.dustindiaz.com