Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>jQuery.extend浅拷贝代码实现</title>
</head>
<body>
    <div id="app">
        extend 用法:<br>
        jQuery.extend( target [, object1 ] [, objectN ] )        Returns: Object
        <br>
        <a href="https://api.jquery.com/jQuery.extend/" target="_blank">jQuery.extend API</a>
        <br>
        jQuery.extend( [deep ], target, object1 [, objectN ] )       Returns: Object
        <br>
        <a href="https://api.jquery.com/jQuery.extend/" target="_blank">jQuery.fn.extend API</a>
    </div>
<!--     <script src="./jquery-3.4.1.js">
    </script> -->
    <script src="https://unpkg.com/jquery@3.4.1/dist/jquery.js"></script>
    <script>
        // 浅拷贝实现
        $.extend = function(){
            // options 是扩展的对象object1,object2...
            var options,
            // object对象上的键
            name,
            // copy object对象上的值,也就是是需要拷贝的值
            copy,
            // 扩展目标对象,可能不是对象,所以或空对象
            target = arguments[0] || {},
            // 定义i为1
            i = 1,
            // 定义实参个数length
            length = arguments.length;
            // 只有一个参数时
            if(i === length){
                target = this;
                i--;
            }
            for(; i < length; i++){
                // 不是underfined 也不是null
                if((options = arguments[i]) !=  null){
                    for(name in options){
                        copy = options[name];
                        // 防止死循环,continue 跳出当前此次循环
                        if ( name === "__proto__" || target === copy ) {
                            continue;
                        }
                        if ( copy !== undefined ) {
                            target[ name ] = copy;
                        }
                    }
                }

            }
            // 最后返回目标对象
            return target;
        }
    </script>
    <script>
        //  extend 用法:
        // ```
        // jQuery.extend( target [, object1 ] [, objectN ] )

        // jQuery.extend( [deep ], target, object1 [, objectN ] )
        // ```

        // 1. jQuery.extend( target)
        var result1 = $.extend({
            job: '前端开发工程师',
        });

        console.log(result1, 'result1', result1.job); // $函数 加了一个属性 job  // 前端开发工程师

        // 2. jQuery.extend( target, object1)
        var result2 = $.extend({
            name: '若川',
        },
        {
            job: '前端开发工程师',
        });

        console.log(result2, 'result2'); // { name: '若川', job: '前端开发工程师' }

        // deep 深拷贝
        // 3. jQuery.extend( [deep ], target, object1 [, objectN ] )
        // var result3 = $.extend(true,  {
        //     name: '若川',
        //     other: {
        //         mac: 0,
        //         ubuntu: 1,
        //         windows: 1,
        //     },
        // }, {
        //     job: '前端开发工程师',
        //     other: {
        //         mac: 1,
        //         linux: 1,
        //         windows: 0,
        //     }
        // });
        // console.log(result3, 'result3');
        // deep true
        // {
        //     "name": "若川",
        //     "other": {
        //         "mac": 1,
        //         "ubuntu": 1,
        //         "windows": 0,
        //         "linux": 1
        //     },
        //     "job": "前端开发工程师"
        // }
        // deep false
        // {
        //     "name": "若川",
        //     "other": {
        //         "mac": 1,
        //         "linux": 1,
        //         "windows": 0
        //     },
        //     "job": "前端开发工程师"
        // }

    </script>
</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console