This post has been imported from my previous blog. I did my best to parse XML properly, but it might have some errors.
If you find one, send a Pull Request.
Recently I’ve been doing a few things with http cookies. I went through the specification and I know path-match and domain-match, hell yeah! One of the results of this trip was a nice JS module pattern found in a jQuery plugin for cookies. Let’s take a look!
In the line one to nine, a module method is created. If an AMD is found, then the passed factory function is used in the define. Otherwise a standard module pattern, with calling a function with a dependency passing is used. In lines 9-11 the real factory function is provided (that would be a whole standard module). The defined function is passed as a factory to the function defined above.
Interested in learning more about topics like this? Click here to join my newsletter. No spam. Meaningful content only.
You can ship this code with AMD or without and it will work in both scenarios. What a pleasant way of providing library aware of its dependency resolving environment!