Add an examples of CoffeeScript

This commit is contained in:
Namhyeon Go 2022-11-29 02:38:11 +09:00
parent f847a29b09
commit 327ef6c810
3 changed files with 14 additions and 2 deletions

4
app.js
View File

@ -228,7 +228,7 @@ function require(FN) {
} }
// compile // compile
T = "(function(global){var module=new require.__ModuleObject__();return(function(exports,require,module,__filename,__dirname){" T = "(function(global){var module=new require.__ModulePrototype__();return(function(exports,require,module,__filename,__dirname){"
+ '"use strict";' + '"use strict";'
+ T + T
+ "\n\nreturn module.exports})(module.exports,global.require,module,__filename__,__dirname__)})(require.__global__);\n\n////@ sourceURL=" + "\n\nreturn module.exports})(module.exports,global.require,module,__filename__,__dirname__)})(require.__global__);\n\n////@ sourceURL="
@ -256,7 +256,7 @@ function require(FN) {
return cache[FN]; return cache[FN];
} }
require.__global__ = this; require.__global__ = this;
require.__ModuleObject__ = function() { require.__ModulePrototype__ = function() {
this.exports = {}; this.exports = {};
}; };
require.__getDirName__ = function(path) { require.__getDirName__ = function(path) {

View File

@ -1,3 +1,5 @@
fortune = require "lib/fortune.coffee"
song = ["do", "re", "mi", "fa", "so"] song = ["do", "re", "mi", "fa", "so"]
singers = {Jagger: "Rock", Elvis: "Roll"} singers = {Jagger: "Rock", Elvis: "Roll"}
@ -22,5 +24,6 @@ main = (args) ->
console.log bitlist.join(',') console.log bitlist.join(',')
console.log JSON.stringify(kids) console.log JSON.stringify(kids)
console.log "Hello world, CoffeeScript" console.log "Hello world, CoffeeScript"
console.log fortune.sayFortune("Foutune!")
exports.main = main exports.main = main

9
lib/fortune.coffee Normal file
View File

@ -0,0 +1,9 @@
###
Fortune Cookie Reader v1.0
Released under the MIT License
###
sayFortune = (fortune) ->
console.log fortune # in bed!
exports.sayFortune = sayFortune