- ·上一篇文章:CoffeeScript 回调绑定
- ·下一篇文章:CoffeeScript 不使用 jQuery 的 Ajax 请求
当前位置:K88软件开发 → 文章中心 → 编程语言 → JavaScript → CoffeeScript → 文章内容
CoffeeScript 创建 jQuery 插件
由 珍珍阿姨 创建,Carrie 最后一次修改 2016-08-12 创建 jQuery 插件问题你想用CoffeeScript来创建jQuery插件。解决方案# 参考 jQuery$ = jQuery# 给 jQuery 添加插件对象$.fn.extend # 把 pluginName 改成你的插件名字。 pluginName: (options) -> # 默认设置 settings = option1: true option2: false debug: false # 合并选项与默认设置。 settings = $.extend settings, options # Simple logger. log = (msg) -> console?.log msg if settings.debug # _Insert magic here._ return @each ()-> log "Preparing magic show." # 你可以使用你的设置了。 log "Option 1 value: #{settings.option1}"讨论这里有几个关于如何使用新插件的例子。JavaScript$("body").pluginName({ debug: true});CoffeeScript$("body").pluginName debug: true
CoffeeScript 创建 jQuery 插件