Ext对原生javaScript对象的扩展

Ext.Object相关的方法使用

  • chain 把当前传入对象作为新创建的对象的原型
	var obj = {
			name:'giserDev',
			age:10
		};
		
	var result = Ext.Object.chain(obj);
	alert(result.name);// giserDev
	alert(result.age);// 10
	alert(result.hasOwnProperty('name'));// false
  • each 迭代
   var obj = {
   	name:'giserDev',
   	age:12,
   	sex:'boy'
   };
   
   Ext.Object.each(obj, function(key, val, self){
   	alert(key + " : " + val);
   	if (val == 12){
   		return false;// 此时会停止迭代	
   	}
   });
  • fromQueryString
	var str = "name=giserDev&age=18";
   var obj = Ext.Object.fromQueryString(str);
   alert(Ext.encode(obj));
  • toQueryObjects
   var obj = {
   	name:'张三',
   	age:20,
   	fav:{
   		fav1:'sleep',
   		fav2:'paly',
   		fav3:'eat'
   	}
   };
   
   var arr = Ext.Object.toQueryObjects("user", obj, true);
   console.info(arr);
  • toQueryString
	var obj = {
		name:'李四',
		age:30
	};
	
	var str = Ext.Object.toQueryString(obj);
	alert(str);

Ext.Number相关的方法使用

//	Checks whether or not the passed number is within a desired range. 
	alert(Ext.Number.constrain(5, 0, 10));
	alert(Ext.Number.randomInt(1,30));
	alert(Ext.Number.toFixed(3.1415926, 3));

Ext.String

	alert(Ext.String.capitalize("gis"));
	alert(Ext.String.ellipsis("www.giserdev.com",9));

Ext.Array

  • clean
	var arr = [3, 5, null, '', 9];
	alert(Ext.Array.clean(arr));
  • diference
	var arr1 = [1,2,3];
	var arr2 = [2,3,5];
	alert(Ext.Array.difference(arr1, arr2));
  • each
	var arr = [1,2,3,4,5];
   Ext.Array.each(arr, function(item){
   	//	当返回false时,会直接停止迭代
   	if (item > 4) {
   		return false;
   	}
   	alert(item);
   });

Ext.Function

  • defer
	// defer 3000毫秒后执行showColor方法
	Ext.Function.defer(showColor, 3000);

Ext.Date

  • between
	// between 判断时间是否在指定的区间
alert(Ext.Date.between(new Date(2020,11,27), new Date(2020,11,26), new Date(2020,11,28)));
  • format
	// format 格式化
alert(Ext.Date.format(new Date(), 'Y-m-d H:i:s'));
  • parse
	// parse
alert(Ext.Date.parse('2020-11-27 22:21:17', 'Y-m-d H:i:s').toLocaleString());
  • parseDate
alert(Ext.Date.parseDate('2020-11-27 22:21:17', 'Y-m-d H:i:s'));
上一篇:大量SQL的解决方案——sdmap


下一篇:Centos 升级python版本(yum 安装方式)