如下是一个jq-plugin的模块加载器预判,这样的代码如何用coffee写呢?
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory)
} else if (typeof exports === 'object') {
// CommonJS
factory(require('jquery'))
} else if (typeof define === 'function' && define.cmd) {
// CMD
define(function (require) {
require('jquery')
factory($)
})
} else {
window.Validator = factory(jQuery)
}
}, (function ($) {
// do something
}))
PHP中文网2017-04-10 14:37:45
解决了,如下即可
do (factory) ->
if typeof define is "function" and define.amd
# AMD
define ["jquery"], factory
else if typeof exports is "object"
# CommonJS
factory require("jquery")
else if typeof define is "function" and define.cmd
# CMD
define (require) ->
require "jquery"
factory $
return
else
window.Validator = factory(jQuery)
return
factory = () ->