jsp文件中jsp
var alertLogic; $(document).ready(function(){ alertLogic = new AlertLogic("alert-test"); });
======================================================================= alert.js文件中this
var AlertLogic = function(dataListId){ //對象屬性 this.dataId = dataListId; this._onCreate(); }; //經過prototype擴展對象實例方法,一樣適用於String AlertLogic.prototype = { /*初始化方法 *主要聲明一些變量,畫面初始化等 */ _onCreate : function () { var logic = this; ... logic._initCommandSet(); }, /*畫面事件聲明*/ _initCommandSet : function () { //點擊事件 $(".clickTest").click(function(){ ... return false; }); }, }; String.prototype.startWith = function(str){};