Skip to content

Instantly share code, notes, and snippets.

@xiaojue
Last active December 25, 2015 11:59
Show Gist options
  • Save xiaojue/6972903 to your computer and use it in GitHub Desktop.
Save xiaojue/6972903 to your computer and use it in GitHub Desktop.
bad amd
define("someapp.js",["a","b","c","d","e","f","g","h","i","j","k"],function(a,b,c,d,e,f,g,h,i,j,k){
});
//what the fuck? 这书写维护起来。。简直了。
//a.js
define("a",[],function(){
var a = document.getElementById("a");
return a;
});
define("someapp.js",["a"],function(require,exprots,module){
var div = document.createElement("div");
div.id = "a";
document.body.appendChild(div);
var a = require("a");
console.log(a) //null;
//这啥玩意啊。。完全不符合预期和逻辑啊?
//其实这就是amd的本质,先加载,然后运行,然后保存结果,然后等着被你调用。
//cmd 则是,加载完毕保存代码,调用运行时再解析结果,返回。
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment