我正在尝试构建一个表示HTML组件组合的js对象。在此对象的构造函数中,div
元素的id应作为参数给出。我的问题是为什么当给定的字符串用作jQuery选择器并且选定的元素被保存为该对象的字段时,我无法使用jQuery方法。
class Element
constructor: (id) ->
@form = $(id)
addNewClass: (text) ->
@form.addClass(text)
element = new Element '#element'
element.addNewClass 'the_class'
<div id='element'></div>
P.S:如果重要的话,我正在研究rails环境中的ruby