Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jQuery/Coffeescript访问父类_Jquery_Coffeescript - Fatal编程技术网

如何使用jQuery/Coffeescript访问父类

如何使用jQuery/Coffeescript访问父类,jquery,coffeescript,Jquery,Coffeescript,情况: 我有一个名为DrawLogic的类,它看起来像(在coffeescript中): 稍后在HTML页面中,我创建了“dynmical constans”,即来自服务器程序的名称,我只想使用/type/一次 <script> DrawLogic.NameSpaceName='orion42'; .... </script> 但是我在我的“DrawLogic类”中,如果我在类范围内使用“=>”i where,并且在this.NameSpaceName中使用thi

情况:

我有一个名为DrawLogic的类,它看起来像(在coffeescript中):

稍后在HTML页面中,我创建了“dynmical constans”,即来自服务器程序的名称,我只想使用/type/一次

<script>
DrawLogic.NameSpaceName='orion42'; 
.... 
</script> 
但是我在我的“DrawLogic类”中,如果我在类范围内使用“=>”i where,并且在
this.NameSpaceName
中使用this或(@)where fine(而不是
window.DrawLogic.NameSpaceName
),但是我松开了选择器的“元素”

那怎么办?有没有比使用“window.DrawLogic.NameSpaceName”更好的方法来引用我所在的类?我不想重复我自己

要说清楚,我只需要键入“DrawLogic”4次(3次在coffescript中,一次在HTML中,但现在我必须在jQuery extendet函数中的每个引用中使用它:-(


有更好的解决方案吗?

当你说你在
DrawLogic
内部时,你说得不对:

class DrawLogic 
    init: ->
        jQuery.fn.td_data = (attr_name) ->
            # Here you're not really inside DrawLogic anymore.
Inside
td_data
无论调用者说你在里面,你都在里面,这是标准的JavaScript行为。上述行为相当于:

f = (attr_name) -> #...
class DrawLogic
    init: -> jQuery.fn.td_data = f
除非您在
init
中有
td\u data
使用的局部变量

如果
window.DrawLogic.NameSpaceName
太多,则应该能够使用
DrawLogic.NameSpaceName
或使用闭包:

class DrawLogic
    init: ->
        DL = @constructor
        jQuery.fn.td_data = (attr_name) ->
            # Use DL.NameSpaceName in here

是的,错别字,我改正了
f = (attr_name) -> #...
class DrawLogic
    init: -> jQuery.fn.td_data = f
class DrawLogic
    init: ->
        DL = @constructor
        jQuery.fn.td_data = (attr_name) ->
            # Use DL.NameSpaceName in here