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;
		}
		
	
	
	
}

你可能感兴趣的:(js面向对象写法,一个小例子)