| Page 1 of 1 | [ 5 posts ] |
|
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? |
|
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? |
|
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?
|
|
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.
|
|
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 |
| Page 1 of 1 | [ 5 posts ] |
| 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 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group