Created
September 22, 2014 03:57
-
-
Save vdurmont/518197dbe0714053e0ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (root, factory) { | |
if (typeof define === 'function' && define.amd) { | |
define(factory); | |
} else { | |
root.Hello = factory(); | |
} | |
}(this, function() { | |
return function() { | |
var done = false; | |
return { | |
print: function(name) { | |
if (!name) { | |
name = "World"; | |
} | |
console.log("Hello "+name+"!"); | |
done = true; | |
}, | |
hasPrint: function() { | |
return done; | |
} | |
} | |
} | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Hello = function() { | |
var done = false; | |
return { | |
print: function(name) { | |
if (!name) { | |
name = "World"; | |
} | |
console.log("Hello "+name+"!"); | |
done = true; | |
}, | |
hasPrint: function() { | |
return done; | |
} | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>AMD example</title> | |
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js"></script> | |
<script type="text/javascript"> | |
requirejs.config({ | |
"paths": { | |
"Hi": "./hello-amd" | |
} | |
}); | |
require(['Hi'], function(Hi) { | |
var h = new Hi(); | |
console.log(h.hasPrint()); | |
h.print(); | |
console.log(h.hasPrint()); | |
h.print("Vincent"); | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Basic example</title> | |
<script type="text/javascript" src="hello.js"></script> | |
<script type="text/javascript"> | |
var h = new Hello(); | |
console.log(h.hasPrint()); | |
h.print(); | |
console.log(h.hasPrint()); | |
h.print("Vincent"); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment