[ 5 posts ]

mike sun

  • Username: msun4
  • Joined: Tue Jan 10, 2012 11:03 am
  • Posts: 2
  • Offline
  • Profile

YUI.use()

Post Posted: Tue Jan 10, 2012 11:32 am
+0-
I have just begun to learn YUI, and have a question about the YUI.use() constructor.

I currently have 10 javascript files in my project and every file is coded like this:

file1.js:
YUI().use("a","b","c", function(Y) {
...
});

file2.js:
YUI().use("a","b","c", function(Y) {
...
});

file3.js:
YUI().use("a","b","c", function(Y) {
...
});

etc.

I have all 10 javascript files included in each html page, but I am wondering if the code has to be repetitive like this, to use the same modules over and over again?

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: YUI.use()

Post Posted: Tue Jan 10, 2012 12:48 pm
+0-
You are looking at it backwards ;)

Try using it like this:

https://gist.github.com/1275713

Where you have one central YUI instance that uses the modules from different files.

Make sense?

mike sun

  • Username: msun4
  • Joined: Tue Jan 10, 2012 11:03 am
  • Posts: 2
  • Offline
  • Profile

Re: YUI.use()

Post Posted: Tue Jan 10, 2012 11:06 pm
+0-
I see what you're doing, but with your example, I still would have to repeat the same modules for each js file using the "requires" attribute, so why is YUI.add() preferred over YUI.use() when both approach work the same?

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: YUI.use()

Post Posted: Wed Jan 11, 2012 6:10 am
+0-
The difference is that you need to create stand alone modules in the separate files, then have one YUI instance that creates and uses those modules. Then you only have one sandbox and one place that your code is instantiated.

Ryan Grove

YUI Developer

  • Username: rgrove
  • Joined: Tue Dec 09, 2008 9:55 pm
  • Posts: 275
  • Location: Portland, OR
  • Twitter: yaypie
  • GitHub: rgrove
  • Gists: rgrove
  • IRC: rgrove
  • YUI Developer
  • Offline
  • Profile
Tags:

Re: YUI.use()

Post Posted: Wed Jan 11, 2012 2:22 pm
+0-
Relevant documentation on YUI().use() and YUI.add() is here:

1. http://yuilibrary.com/yui/docs/yui/#und ... ing-yuiuse
2. http://yuilibrary.com/yui/docs/yui/#yuiadd
  [ 5 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum