javascript - Is the _extend method used to traverse object properties? How to understand the two parameters?
世界只因有你
世界只因有你 2017-05-18 11:01:02
0
1
482

Can anyone explain:
Why does _extend appear twice? What do they mean? Does it mean the default method is called? ?
The first time is Base.prototype._extend.
Especially the second time, what do the destination and source represent?

 _extend = function self(destination, source) {
     ......
 }

The following is the part of the code that caused my confusion:

define(function(){
var Base = function(){};
Base.prototype._extend = function(dest, src){
    var _complete,
    _extend,
    _isObject;
    _isObject = function(o){
        return (Object.prototype.toString.call(o) === '[object Object]' || Object.prototype.toString.call(o) === '[object Array]');
    },
    _extend = function self(destination, source) {
        var property;
        for (property in destination) {
            if (destination.hasOwnProperty(property)) {
                if (_isObject(destination[property]) && _isObject(source[property])) {
                    self(destination[property], source[property]);
                };

                if (source.hasOwnProperty(property)) {
                    continue;
                } else {
                    source[property] = destination[property];
                }
            }
        }
    }
    //省略部分代码...
    }})
世界只因有你
世界只因有你

reply all(1)
刘奇

_extend The first one is variable declaration, and the second one is variable assignment.

The function is to traverse the destination variable and copy its internal attributes to the source. If the attribute already exists on the source, it will not be copied.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template