---
title: "Ext.apply 学习"
author: "flyinglife"
date: "2010-04-02T10:27:09Z"
tags: []
categories: ["Web前端"]
slug: "ext-apply"
draft: false
lastmod: "2010-04-02T10:29:10Z"
id: 630562
url: "https://flyinglife.iteye.com/blog/630562"
---

一： ext.apply用来把参数拷贝到对象中，先看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;
};
 
```

  

 1、两个参数时：直接把【 c  】的所有属性放到【 o  】，并且返回【 o  】，。

 2、三个参数时：先把配置项【defaults】拷贝到【 o  】中，把【 c  】的所有属性放到【 o  】。

 

注意：都会发生属性覆盖。

 

二： 两个参数时