---
title: "extjs源码分析-001(Ext.apply)"
author: "y1d2y3xyz"
date: "2011-02-07T15:15:17Z"
tags: []
categories: ["Web前端"]
slug: "extjs-001-ext-apply"
draft: false
lastmod: "2011-02-07T18:55:59Z"
id: 901498
url: "https://lovebeyond.iteye.com/blog/901498"
---

```java

/**
 * Copies all the properties of config to obj.
 * @param {Object} 继承的对象
 * @param {Object} 新的配置参数--这个值可以为空
 * @param {Object} 新的配置参数--这个值可以为空
 * @return {Object} returns obj 返回复制值后的对象
 * @member Ext apply
 */

Ext.apply = function(o, c, defaults){   
    // no "this" reference for friendly out of scope calls   
    if(defaults){   
        Ext.apply(o, defaults);   
    }   
    if(o && c && typeof c == 'object'){   
        for(var p in c){   
            o[p] = c[p];   
        }   
    }   
    return o;   
}; 
//执行过程是:将c的值和defaults的值拷贝给o,然后返回o对象
//使用方式:
var o = {};
var c = {name:'tom',showName:function(){alert(name);}};
var d = {age:23};
Ext.apply(o,c,d);

```