Ext原码学习之lang-Object.js
// JavaScript Document
(function(){
var TemplateClass = function(){}, ExtObject = Ext.Object = {
chain:Object.create || function(object)
{
TemplateClass.prototype = object;
var result = new TemplateClass();
TemplateClass.prototype = null; return result;
},//Ext.log.info(ExtObject.chain({1:3}));
toQueryObjects:function(name,value,recursive)
{
var self = ExtObject.toQueryObject,objects = [],i,ln;
if(Ext.isArray(value))
{
for(i =0,ln = value.length;i<ln;i++)
{
if(recursive)
{
objects = objects.concat(self(name+'['+i +']', value[i],true));
}
else
{
objects.push({
name:name,
value:value[i]
});
}
}
}
else if(Ext.isObject(value))
{
for(i in value)
{
if(value.hasOwnProperty(i))
{
if(recursive)
{
objects = objects.concat(self(name+'['+i+']',values[i],true));
}
else
{
objects.push({
name:name,
value:value[i]
});
}
}
}
}
else
{
objects.push({
name:name,
value:value
});
} return objects;
},
toQueryString:function(object,recursive)
{
var paramObjects = [],params = [],i,j,ln,paramObject,value; for(i in object)
{
if(object.hasOwnProperty(i))
{
paramObjects = paramObjects.concat(ExtObject.toQueryObjects(i,object[i],recursive));
}
} for(j=0,ln=paramObjects.length;i<ln;j++)
{
paramObject = paramObjects[j];
value = paramObject.value; if(Ext.isEmpty(value))
{
value ='';
}
else if(Ext.isDate(value))
{
value = Ext.Date.toString(value);
} params.push(encodeURIComponent(paramObject.name) + '=' + encodeURIComponent(String(value)));
} return params.join('&');
},
fromQueryString:function(queryString,recursive)
{
var parts = queryString.replace(/^\?/,'').split('&'),
object = {},
temp ,components,name,value,i,ln,part,j,subLn,matchedKeys,matchedName,
keys,key,nextKey; for(i=0,ln = parts.length;i<ln;i++)
{
part = parts[i]; if(part.length>0)
{
components = part.split('=');
name = decodeURIComponent(components[0]);
value = (components[1] !==undefined ) ? decodeURIComponent(components[1]):'';
if(!recursive)
{
if(object.hasOwnProperty(name))
{
if(!Ext.isArray(object[name]))
{
object[name] = [object[name]];
} object[name].push(value);
}
else
{
object[name] = value;
}
}
else
{
matchedKeys = name.match(/(\[):?([^\]]*)\]/g);
matchedName = name.match(/^([^\[]+)/); if (!matchedName) {
throw new Error('[Ext.Object.fromQueryString] Malformed query string given, failed parsing name from "' + part + '"');
} name = mathedName[0];
keys = []; if(matchedKeys === null)
{
object[name] = value;
continue;
} for (j = 0, subLn = matchedKeys.length; j < subLn; j++) {
key = matchedKeys[j];
key = (key.length === 2) ? '' : key.substring(1, key.length - 1);
keys.push(key);
} keys.unshift(name); temp = object; for (j = 0, subLn = keys.length; j < subLn; j++)
{
key = keys[j]; if (j === subLn - 1) {
if (Ext.isArray(temp) && key === '') {
temp.push(value);
}
else {
temp[key] = value;
}
}
else {
if (temp[key] === undefined || typeof temp[key] === 'string') {
nextKey = keys[j+1]; temp[key] = (Ext.isNumeric(nextKey) || nextKey === '') ? [] : {};
} temp = temp[key];
}
}
}
} }
return object;
},
each:function(object,fn,scope)
{
for(var property in object)
{
if(object.hasOwnProperty(property))
{
if(fn.call(scope || object ,property,object[property],object)===false)
{
return;
}
}
}
},
merge:function(destination)
{
var i =1,ln = arguments.length,
mergeFn = ExtObject.merge,
cloneFn = Ext.clone,
object,key,value,sourceKey;
for(;i<ln;i++)
{
object = arguments[i]; for(key in object)
{
value = object[key]; if(value && value.constructor === Object)
{
sourceKey = destination[key];
if(sourceKey && sourceKey.constructor===Object){
mergeFn(sourceKey,value);
}
else
{
destination[key] = cloneFn(value);
}
}
else
{
destination[key]=value;
}
}
}
} ,
mergeIf: function(destination) {
var i = 1,
ln = arguments.length,
cloneFn = Ext.clone,
object, key, value; for (; i < ln; i++) {
object = arguments[i]; for (key in object) {
if (!(key in destination)) {
value = object[key]; if (value && value.constructor === Object) {
destination[key] = cloneFn(value);
}
else {
destination[key] = value;
}
}
}
} return destination;
},
getKey:function(object,value)
{
for(var property in object)
{
if(object.hasOwnProperty(property) && object[property] === value)
{
return property;
}
} return null;
},
getValues:function(object){
var values = [],property;
for(property in object)
{
if(object.hasOwnProperty(property))
{
values.push(object[property]);
}
} return values;
},
//获取objects key
getKeys:(typeof Object.keys == 'function') ? function(object){
if(!object){
return [];
}
return Object.keys(object);
} :function(object){
var keys = [],property; for(property in object)
{
if(object.hasOwnProperty(property))
{
keys.push(property);
}
}
return keys;
},
//获取objects property count
getSize:function(object){
var size = 0,property; for(property in object)
{
if(object.hasOwnProperty(property))
{
size++;
}
}
return size;
},
//判断对象是否有属性
isEmpty:function(object)
{
for(var key in object)
{
if(object.hasOwnProperty(key))
{
return false;
}
} return true;
},
//判断对象是否相等
equals: (function() {
var check = function(o1, o2) {
var key; for (key in o1) {
if (o1.hasOwnProperty(key)) {
if (o1[key] !== o2[key]) {
return false;
}
}
}
return true;
}; return function(object1, object2) { // Short circuit if the same object is passed twice
if (object1 === object2) {
return true;
} if (object1 && object2) {
// Do the second check because we could have extra keys in
// object2 that don't exist in object1.
return check(object1, object2) && check(object2, object1);
} else if (!object1 && !object2) {
return object1 === object2;
} else {
return false;
}
};
})(),
classify:function(object)
{
var prototype = object,objectProperties = [],
propertyClassMap = {},
objectClass = function(){
var i = 0,ln = objectProperties.length,property; for(;i<ln;i++)
{
property = objectPropertyes[i];
this[property] = new propertyClassesMap[property]();
}
},key,value; for(key in object)
{
if(object.hasOwnProperty(key))
{
value = object[key]; if(value && value.constructor === Object)
{
objectProperties.push(key);
propertyClassMap[key] = ExtObject.classify(value);
}
}
} objectClass.property = property; return objectClass;
} }; Ext.merge = Ext.Object.merge; Ext.mergeIf = Ext.Object.mergeIf; /**
*
* @member Ext
* @method urlEncode
* @inheritdoc Ext.Object#toQueryString
* @deprecated 4.0.0 Use {@link Ext.Object#toQueryString} instead
*/
Ext.urlEncode = function() {
var args = Ext.Array.from(arguments),
prefix = ''; // Support for the old `pre` argument
if ((typeof args[1] === 'string')) {
prefix = args[1] + '&';
args[1] = false;
} return prefix + ExtObject.toQueryString.apply(ExtObject, args);
}; /**
* Alias for {@link Ext.Object#fromQueryString}.
*
* @member Ext
* @method urlDecode
* @inheritdoc Ext.Object#fromQueryString
* @deprecated 4.0.0 Use {@link Ext.Object#fromQueryString} instead
*/
Ext.urlDecode = function() {
return ExtObject.fromQueryString.apply(ExtObject, arguments);
}; }());
Ext原码学习之lang-Object.js的更多相关文章
- Ext原码学习之Ext.js
1 // JavaScript Document 2 //定义全局Ext变量 3 var Ext = Ext ||{}; 4 Ext._startTime = new Date().getTime() ...
- Ext原码学习之Ext-more.js
// JavaScript Document Ext.apply(Ext,{ userAgent:navigator.userAgent.toLowerCase(), cache:{}, isSeed ...
- Ext原码学习之lang-Array.js
// JavaScript Document //Array 方法 (function(){ var arrayPrototype = Array.prototype, slice = arrayPr ...
- JDK1.8源码(一)——java.lang.Object类
本系列博客将对JDK1.8版本的相关类从源码层次进行介绍,JDK8的下载地址. 首先介绍JDK中所有类的基类——java.lang.Object. Object 类属于 java.lang 包,此包下 ...
- Java源码学习 -- java.lang.StringBuilder,java.lang.StringBuffer,java.lang.AbstractStringBuilder
一直以来,都是看到网上说“ StringBuilder是线程不安全的,但运行效率高:StringBuffer 是线程安全的,但运行效率低”,然后默默记住:一个是线程安全.一个线程不安全,但对内在原因并 ...
- Java源码学习 -- java.lang.String
java.lang.String是使用频率非常高的类.要想更好的使用java.lang.String类,了解其源代码实现是非常有必要的.由java.lang.String,自然联想到java.lang ...
- Underscore.js 源码学习笔记(上)
版本 Underscore.js 1.9.1 一共 1693 行.注释我就删了,太长了… 整体是一个 (function() {...}()); 这样的东西,我们应该知道这是一个 IIFE(立即执行 ...
- 【 js 基础 】【 源码学习 】源码设计 (持续更新)
学习源码,除了学习对一些方法的更加聪明的代码实现,同时也要学习源码的设计,把握整体的架构.(推荐对源码有一定熟悉了之后,再看这篇文章) 目录结构:第一部分:zepto 设计分析第二部分:undersc ...
- Underscore.js 源码学习笔记(下)
上接 Underscore.js 源码学习笔记(上) === 756 行开始 函数部分. var executeBound = function(sourceFunc, boundFunc, cont ...
随机推荐
- Java Swing 如何设置图片大小
如下两行代码搞定: Image image = new ImageIcon("Img/ackground.jpg").getImage();// 这是背景图片 .png .jpg ...
- Mysql 8.0版本以上和8.0以下jar包版本 需要注意的 URL连接参数useSSL、serverTimezone 相关问题
在语法上的需要注意的: MySQL 8.0 以下版本 - JDBC 驱动名及数据库 URL static final String JDBC_DRIVER = "com.mysql.jdbc ...
- SSH公/私秘钥的生成及使用
如果使用GitHub比较多的朋友,对SSH Key肯定也不陌生,当我们SSH进行代码的pull&push时,往往需要我们配置SSH Key. 如果Linux用的多朋友,肯定对SSH Key都很 ...
- css 基础 css引入方式
color:red; //改变颜色 font-size:18px : //改变文字大小 background-color : blue; //设置背景颜色 width:100px ://设置宽度 he ...
- 初识python: 字典
使用数据字典,编写一个多级菜单: 需求:每一级可返回上级,可退出. 多级菜单 #!/user/bin env python # author:Simple-Sir # time:20180915 # ...
- quasar框架在store中使用router跳转页面报错
网上一通百度,终于在这篇博客中找到原因. https://www.cnblogs.com/remly/p/12995936.html 原因是: 在router中导出了一个工厂函数, 既然是一个函数, ...
- 简述伪共享和缓存一致性MESI
什么是伪共享 计算机系统中为了解决主内存与CPU运行速度的差距,在CPU与主内存之间添加了一级或者多级高速缓冲存储器(Cache),这个Cache一般是集成到CPU内部的,所以也叫 CPU Cache ...
- 如何对K8s进行考核?Kuberhealthy来打个样!
2019年11月,在圣地亚哥KubeCon,我们发布了kuberhealth 2.0.0--将kuberhealthy作为合成监测的Kubernetes operator.这个新功能为开发人员提供了创 ...
- 计算机二级考试office专题之绝对引用相对引用
- Android学习笔记2
4,用intent在activity之间传递数据(两个Activity可能不是在一个应用程序中) (1),从MainActivity向HelloActivity传递参数123 package com. ...