如何使用jQuery包装集扩展类?

时间:2015-03-12 18:40:35

标签: jquery coffeescript

以下几乎可以运作......

$el = ->
$el:: = $ '#test'
new class extends $el
  constructor: ->
    @append '<h1>Worked!</h1>'


    # this will overflow the stack
    @find('[role=test2]').append '<h2>Also Worked!</h2>'

此处示例:http://jsfiddle.net/66a3jdot/

1 个答案:

答案 0 :(得分:0)

答案是盯着我的脸......

new class
  @:: = $ '#test'
  constructor: ->
    @append '<h1>Worked!</h1>'
    @find('[role=test2]').append '<h2>Also Worked!</h2>'

http://jsfiddle.net/wycleffsean/66a3jdot/2/