-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathuniversal.js
63 lines (52 loc) · 1.63 KB
/
universal.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Ejemplo base */
(function(root, factory) { //[1]
if(typeof define === 'function' && define.amd) { //[2]
define(['mustache'], factory);
} else if(typeof module === 'object' && //[3]
typeof module.exports === 'object') {
var mustache = require('mustache');
module.exports = factory(mustache);
} else { //[4]
root.UmdModule = factory(root.Mustache);
}
}(this, function(mustache) { //[5]
var template = '<h1>Hello <i>{{name}}</i></h1>';
mustache.parse(template);
return {
sayHello:function(toWhom) {
return mustache.render(template, {name: toWhom});
}
};
}));
/* Ejemplo adicional */
"use strict";
(function(exports) {
exports.StringSet = function () {
this.data = {};
// arguments is not an array; borrow forEach
Array.prototype.forEach.call(arguments, function(elem) {
this.add(elem);
}, this); // pass "this" on to the function
}
exports.StringSet.prototype.add = function(elem) {
if (typeof elem !== "string") {
throw new TypeError("Argument is not a string: "+elem);
}
this.data[elem] = true;
return this; // allow method chaining
}
exports.StringSet.prototype.contains = function(elem) {
// Comparison ensures boolean result
return this.data[elem] === true;
}
}(typeof exports === "undefined"
? (this.strset = {})
: exports));
// En NODE JS:
var strset = require("./strset");
var s = new strset.StringSet();
//En Browser:
<script src="strset.js"></script>
<script>
var s = new strset.StringSet();
</script>