1. 程式人生 > >js面向物件寫法,一個小例子

js面向物件寫法,一個小例子

/**
 * 
 * 這是一個校驗檔案
 */
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;
		}
		
	
	
	
}