js面向物件寫法,一個小例子
阿新 • • 發佈:2019-01-25
/** * * 這是一個校驗檔案 */ var MyValidation = function(){ //校驗資料庫 this.validDatabase = function(source){ if(source==null){ return false; } var databaseArray = new Array("select","delete","drop","database","insert","table","show","update","create","truncate"); var flag = false; for(var i = 0 ; i < databaseArray.length ; i++){ flag = this.isContain(source,databaseArray[i]); if(flag) break; } return flag; } //判斷主串是否包含子串 this.isContain=function(parent,child){ if(parent==null||child==null){ return false; } if( parent.indexOf(child) >= 0 ) return true; return false; } }