PDA

View Full Version : javascript newbie.. help?



arctu
6 Nov 2006, 3:11 AM
thanks for your great work jack!

i've been messing up with yui-ext for a while now. after analyzing your examples i managed to understand most of them. what i cant seem to get is in every object, whats the return { for?

example from BasicDialog..


// return a public interface
return {
init : function(){
showBtn = getEl('show-dialog-btn');
// attach to click event
showBtn.on('click', this.showDialog, this, true);

getEl('theme-btn').on('click', toggleTheme);
},

showDialog : function(){
if(!dialog){ // lazy initialize the dialog and only create it once
dialog = new YAHOO.ext.BasicDialog("hello-dlg", {
modal:true,
autoTabs:true,
width:500,
height:300,
shadow:true,
minWidth:300,
minHeight:300
});


any hints?

jack.slocum
6 Nov 2006, 4:29 AM
It's a combo of two things. The first function actually executes immediately, which is why it ends in (). It is there to create the private scope. It returns an object (the public interface) who's functions are visible to everyone. Does that make sense?

There's a recent thread where I explained this a little better (with some code too).

arctu
6 Nov 2006, 6:44 AM
well, actually i understands what the init function does etc... what i want to know is why must there be a "return {"?.. what does it actually do? because all this while i have only done simple JS and use simple objects. I've never encounter a "return {...}" in an object..

thanks for your help. it must be hard to response to the posts in this forum..

tryanDLS
6 Nov 2006, 8:07 AM
If you're looking for explanations of some of the OO concepts used in yui-ext, including object creation, public vs private methods/properties, statics, constructors, etc., the following are good starting points. These sites have some good examples that illustrate a lot of the concepts in a much simpler context than the yui-ext code.

http://phrogz.net/JS/Classes/OOPinJS.html
http://kevlindev.com/tutorials/javascript/inheritance/index.htm
http://www.crockford.com/javascript/

Also, another post was asking about a JS reference. Another good online one is the Mozilla ref:
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference

Another 'kitchen sink' collection of JS things - regex, debugging, strings, objects, cookies, forms, etc.
http://home.cogeco.ca/~ve3ll/jstutor0.htm

Jack, maybe some of these links could go into a sticky post somewhere, so developers have a common starting point??

HTH :)

jack.slocum
6 Nov 2006, 4:29 PM
Great idea. I will sticky it.

arctu
6 Nov 2006, 5:20 PM
thanks for all the help guys.. =)

Loony2nz
7 Nov 2006, 10:08 PM
here is another great site for json examples and description:
http://www.dustindiaz.com/json-for-the-masses/

BTW: dustin diaz's whole site is a boon to the YUI community.

sjivan
27 Nov 2006, 10:35 PM
http://www.dustindiaz.com/javascript-private-public-privileged/ has a good explanation of the pattern Jack uses to create a singleton object on application initialization.

The article also mentions that some people think that it's got a strange or rather unusual syntax, which I did too until I understood whats actually going on.

Sanjiv

Animal
30 Nov 2006, 12:09 AM
Here are the definitive references for Javascript DOM methods:

Operations on core DOM elements like Document/Element etc:

http://www.w3.org/TR/DOM-Level-2-Core/ecma-script-binding.html

Operations on HTML-specific extensions of the DOM link table, input etc:

http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html

Herm
30 Nov 2006, 5:29 PM
On a more 'touchy feely' note, I got great benefit from sitting through Douglas Crockfords "Theory of the DOM" and "Advanced Javascript" video lectures here http://developer.yahoo.com/yui/theater/

There are also a few others on that page that I found the time to view and found worthwhile.

Peter

brian.moeskau
30 Nov 2006, 8:17 PM
For anyone who may want a resource that they can read in the bathroom :) I picked up the 5th edition of Javascript: The Definitive Guide by O'Reilly (has a big rhinoceros on the cover). The first section of the book (200+ pages) is a really good, detailed overview of all of the OO concepts used here, written from an app developer point of view. Lots of decent example code.

skyey
13 Mar 2007, 9:53 PM
i have the same as question with author, thank for you help

brian
25 Mar 2007, 10:29 PM
Here's a link to that O'Reilly book on google book search, and it has a lot of pages available for preview: http://books.google.com/books?vid=ISBN0596000480&id=xn5aJpEJSEYC&dq=javascript

Joe
17 Apr 2007, 10:46 AM
On a more 'touchy feely' note, I got great benefit from sitting through Douglas Crockfords "Theory of the DOM" and "Advanced Javascript" video lectures here http://developer.yahoo.com/yui/theater/

There are also a few others on that page that I found the time to view and found worthwhile.

Peter

Great videos! These should be required viewing for anyone doing Ext. So many questions answered.

lummie
30 Apr 2007, 11:44 PM
Apart form a few lines when doing basic html pages I am new to javascript. A C# / Delphi programmer to-date, I am just venturing into the flexible world of Javascript and Ext for a major project. I am blogging my experiences from a c# programmers point of view, starting with javascript and stretching into ext component development as I progress.

It might be useful to others newbies : thinksharp.org (http://www.thinksharp.org)

72
1 May 2007, 8:14 AM
...It might be useful to others newbies : thinksharp.org (http://www.thinksharp.org)

Really recomends, very interesting articles there...easy to get...so check it!

jay@moduscreate.com
9 May 2007, 8:59 AM
Currently reading:
Great for learning OO from the ground up.

http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273/ref=sr_1_1/002-9439369-5593632?ie=UTF8&s=books&qid=1178729929&sr=8-1


http://ec1.images-amazon.com/images/I/51XWseT1BbL._SS500_.jpg

whison
23 Aug 2007, 8:17 AM
Great help for JS newbies like me, thank you all :)

ortizSWF
25 Jan 2008, 7:12 AM
More information...

http://www.itstudy8.org/script.asp

http://www.itstudy8.org/ShowBook.asp?BookId=2499

http://www.itstudy8.org/ShowBook.asp?BookId=1963

Greetings...~o)