Comments (5)
I do not think I quite follow. Could you illustrate it with a code example?
from umd.
In the jQuery plugin I'd like to have a private variable that cannot be read outside the plugin.
And also a public (but not global) variable that can be set in other modules dependent on this jQuery plugin.
from umd.
meanwhile a few js projects went UMD :)
from umd.
Probably something like this then. Since it is a jquery plugin I would expect just AMD and browser globals to be in play, so I used the amdWeb.js example UMD as a baseline:
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
// Browser globals
root.myPlugin = factory(root.jQuery);
}
}(this, function ($) {
// This variable is private just to the jquery plugin
var privateVariable = 'foo';
$.fn.myPlugin = function () {};
// This is a variable that is visible to other code
$.fn.myPlugin.config = {};
return $.fn.myPlugin;
}));
Then if an AMD loader plugin asks for this plugin, it can modify myPlugin.config:
define(['myPlugin'], function (myPlugin) {
myPlugin.config.color = 'blue';
});
from umd.
Thank you very much!
Maybe - for others - it worths to make it a file in the repo.
from umd.
Related Issues (20)
- Readme.md headers are formatted incorrectly HOT 2
- AMD using require sugar syntax
- Start With CommonJS Instead of AMD? HOT 1
- Compatibility with webpack HOT 3
- UMD is not compatible with JavaScript modules HOT 12
- JavaScript Module shim for UMD bundles HOT 1
- Brace_umd project should be included in the README
- es6 module support? HOT 8
- UMD seems to be not quite clear for cases when you need multiple dependencies or none HOT 1
- jQuery compatible (but not required) + AMD + CommonJS? HOT 1
- xmsdk.js HOT 2
- Script Tag usage?
- Checks for CommonJS module environments are not fail-safe HOT 1
- Using UMD to create Singleton Instance across Micro Frontends HOT 1
- Include a history of UMD and when/why to use it
- Strict vs Returning variants with CommonJS support
- UMD should always immediately run factory HOT 1
- optional dependencies HOT 2
- Use UMD with JSDOM?
- templates/jqueryPlugin.js doesn't seem to conform to CommonJS spec HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umd.