2
這是什麼我試着去實現一個例子使用eval來動態調用Coffeescript類安全嗎?
HTML
<div data-js-class="Header"></div>
CoffeeScript的,如果它是完全安全的使用eval()這裏
class Header
constructor: (@root) ->
# Header related code here
$('[data-js-class]').each(->
unless $(this).attr('data-js-loaded') == 'true'
partial_class = eval($(this).attr('data-js-class'))
if typeof partial_class != "undefined"
new partial_class($(this))
$(this).attr('data-js-loaded', 'true')
)
林不知道或是否有一個更好的方法來做到這一點?我嘗試使用window[$(this).attr('data-js-class')]
但它似乎沒有工作,可能是由於使用的CoffeeScript關閉的方式。