Home / Blog / How to easily use a javascript function with YUI 3

History always repeats itself and sometimes that's good. Here's a second chance to be part of it: tmdtc.com

How to easily use a javascript function with YUI 3

ALL YUI 3 code on a page is placed in its own sandbox. This allows several parts of a page to be completely independent, with benefits in maintainability and stability: one sandbox cannot have any effect on another sandbox on the page, and a sandbox only uses the modules it needs. These sandboxes are create with YUI.use :

If you have a function based on YUI that you are going to reuse often, as I had with transitioning MyOwnDB to YUI 3, the best solution is to define it in a module that you'll use in each sandbox that needs it. Defining a module is done with YUI.add which also lets you specify which other modules it depends on. The body of the module is simply adding a namespage to YUI, which will hold all my code, defining the function and putting it under the namespace just created, like this:

Now I can simply use my new module and its associated function in any sandbox I define:

Thanks to Satake and Daniel Cook on the YUI Forum for their advice .

Disponible pour intervention 

Si vous recherchez quelqu'un pour renforcer temporairement votre équipe ou si vous avez besoin d'aide pour que l'IT aide votre société, n'hésitez pas, contactez-moi !

Lun Mar Merc Jeu Ven Sam Dim
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31