0
Radiant::loadCSS = (fn, scope) ->
  head = document.getElementsByTagName("head")[0]
  link = document.createElement("link")
  link.setAttribute "href", "/" + ri.context + "/css/" + @obj + ".css"
  link.setAttribute "rel", "stylesheet"
  link.setAttribute "type", "text/css"
  sheet = undefined
  cssRules = undefined
  if "sheet" of link
    sheet = "sheet"
    cssRules = "cssRules"
  else
    sheet = "styleSheet"
    cssRules = "rules"
  timeout_id = setInterval(->
    try
      if link[sheet] and link[sheet][cssRules].length
        clearInterval timeout_id
        clearTimeout timeout_id
        fn.call scope or window, true, link #LINE THAT ERRORS OUT!!!
    #finally
  , 10)
  timeout_id = setTimeout(->
    clearInterval timeout_id
    clearTimeout timeout_id
    head.removeChild link
    fn.call scope or window, false, link
  , 15000)
  head.appendChild link
  link

したがって、上記はここからリッピングされた関数の私の翻訳です: jQueryなしでコールバック付きのjavascriptを使用してcssファイルを動的にロードする

これをまっすぐなjavascriptで使用した場合はうまく機能しましたが、コーヒーバージョンではie8で問題が発生しています'fn' is null or not an object

そのセクションのレンダリングされた JavaScript は次のとおりです。

timeout_id = setInterval(function() {
  try {
    if (link[sheet] && link[sheet][cssRules].length) {
      clearInterval(timeout_id);
      clearTimeout(timeout_id);
      return fn.call(scope || window, true, link); //ERROR LINE!!!
    }
  } catch (_error) {}
}, 10);

とにかく、私は初めてでtrycatchここで何がうまくいかないのか理解できません。よろしくお願いします!

4

1 に答える 1

1

これはtry/catchとはあまり関係がなく、何らかの理由でそれと関係があると思いfnます.コールバックの実行時に(エラーが示すように)定義されていません. エラーが発生した場合にfn渡されますか?loadCSS

于 2012-05-31T17:25:55.317 に答える