8000 GitHub - inkie/define: simple and quick module definition library in web application. · GitHub
[go: up one dir, main page]

Skip to content
inkiePublic
forked from winsonwq/define

About

simple and quick module definition library in web application.

Resources

Stars

0 stars

Watchers

1 watching

Forks

 
 

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

define

simple and quick module definition library in web application.

quick start

Only considering that all resources has loaded in html file.

<!doctype html>
<!-- import define -->
<script type="text/javascript" src="./lib/define.js"></script>

<!-- load your libraries -->
<script type="text/javascript" src="./scripts/app.js"></script>
<script type="text/javascript" src="./scripts/c.js"></script>
<script type="text/javascript" src="./scripts/a.js"></script>
<script type="text/javascript" src="./scripts/b.js"></script>

dependencies

a.js is depending on b.js, and it's loading before b.js. And use return to define a module.

define('module.a', [], function (exports) {
  return {
    value: 'a'
  };
});

b.js is a standalone module. And use exports.property to extend module.

define('module.b', ['module.a'], function (exports, a) {
  exports.value = a.value + 'b';
});

c.js is a asynchronous module. And use callback to init.

define('module.c', ['module.a', 'module.b'], function (exports, a, b, callback) {
  setTimeout(function () {
    callback({ value: a.value + b.value + 'c' });
  }, 1000);
});

but in app.js, it's depending on the container module (not explicitly define in file).

use(['module'], function (module) {
  console.log(module.a.value);
  console.log(module.b.value);
  console.log(module.c.value);
});

// output
// a
// ab
// aabc

License

Copyright (c) 2013 Wang Qiu (winsonwq@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

simple and quick module definition library in web application.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

0