博客日记
今天寫了一些editor的代碼,學了一些寫框架得東西
(function( global, factory ) {
//應該是為了可以應用在requirejs等庫中
if ( typeof module === "object" && typeof module.exports === "object" ) {
// For CommonJS and CommonJS-like environments where a proper window is present,
// execute the factory and get jQuery
// For environments that do not inherently posses a window with a document
// (such as Node.js), expose a jQuery-making factory as module.exports
// This accentuates the need for the creation of a real window
// e.g. var jQuery = require("jquery")(window);
// See ticket #14549 for more info
module.exports = global.document ?
factory( global, true ) :
function( w ) {
if ( !w.document ) {
throw new Error( "orionEditor requires a window with a document" );
}
return factory( w );
};
} else {
//無模塊環境時
factory( global );
}
// Pass this if window is not defined yet
}(typeof window !== "undefined" ? window : this,function(){}));
在后面的function才是自己的框架的代碼,這段代碼取自jquery,畢竟我還太嫩。。。
這段代碼的作用就是自己寫的私有的方法和一些東西不會污染全局的環境,同時還可以,但是有一些修改了prototype的代碼還是可能會改變其他的代碼。
jquery的思想大概今天了解了一些,是通過創建一個jquery對象,這個對象的功能非常強大,封裝了許多的方法,這樣就會使jquery開發者同樣可以使用原生的js或者其他的庫當然并不可以用JQuery或者$();
每次$()都會返回一個jquery對象。而且還有優雅的鏈式調用。以前比較年輕,但是今天真的是覺得jqeury是一個非常優雅的庫,有很多值得我們去學習的地方。
最后,加油
總結
- 上一篇: PSpice添加SPICE模型
- 下一篇: 直流电机,伺服电机和步进电机的区别