作者TonyQ (骨头)
看板Ajax
标题Re: javascript 的 include 问题?
时间Thu Apr 26 17:48:39 2007
※ 引述《yllan (蓝永伦)》之铭言:
: hello, 我目前写的东西有两个需求,第一个就是希望能够在 javascript 中
: 引入别的 .js 档案,第二个就是希望能够等到引入的 .js 读完以後再执行一
: xxx.js 呼叫 yyy.js, lib.js
: yyy.js 呼叫 lib.js
: zzz.js 呼叫 lib.js
: 我希望每个档案都等到呼叫到的档案载入、init 以後自己才能 init,
: 也就是希望能够 lib.js init -> zzz.js init -> yyy.js init -> xxx.js init
: 就是希望能够按照他们之间相依关系的拓扑排序顺序来呼叫...
: 请问大家有好解法吗?(唉,问题落落长,可能描述得不太好)
可以用 Object的方式引入 ,
然後你只要去判断 Object是否存在,就可以决定是否要引入。
简单来说就类似
#ifndef xxxx
include xxxx
#endif
先去判断还没有引用,再来做引用的动作。
我印象中dojo.js 也是这样玩的
它的lib都写在dojo物件底下
if(typeof dojo=="undefined"){
/*..建置dojo的过程..*/
}
--
String temp="relax"; | Life just like programing
while(buringlife) String.forgot(temp); | to be right or wrong
while(sleeping) brain.setMemoryOut(); | need not to say
stack.push(life.running); | the compiler will
stack.push(scouting.buck()); | answer your life
stack.push(bowling.practice()); | Bone
everything
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.134.27.68