Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alveflo/require
Client side require/include for javascript
https://github.com/alveflo/require
Last synced: 14 days ago
JSON representation
Client side require/include for javascript
- Host: GitHub
- URL: https://github.com/alveflo/require
- Owner: alveflo
- License: mit
- Created: 2014-11-03T19:53:51.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-24T20:03:19.000Z (almost 10 years ago)
- Last Synced: 2023-08-04T01:03:42.385Z (over 1 year ago)
- Language: JavaScript
- Size: 168 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
require
=======Super simple client side require/include for javascript - basically just an ajax call and eval().
### Usage
Again - this few lines of code that imports js-script is just doing the following:
* A synchronous AJAX call to fetch the file
* using eval() to evaluate the scriptThat being said, you'll need to be backed up with a web server in order to get the AJAX call to work.
#### Dependencies
* jQuery#### JS "interface"
In order to export functions and variables they needs to be injected to the objects prototype:
```javascript
this.prototype = {
add: function(a,b) {
return a + b;
},
sub: function(a,b) {
return a - b;
},
mul: function(a,b) {
return a * b;
},
div: function(a,b) {
return a / b;
}
}
```#### Importing and usage
```html
var example = require('example.js');
console.log(example.add(1,2));
// yields 3
console.log(example.sub(1,2));
// yields -1
console.log(example.mul(1,2));
// yields 2
console.log(example.div(1,2));
// yields 0.5
```
### Licence
MIT