Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              var person={
  name:'steven',
  age:28,
  birthday:new Date('1990-01-01'),
  run:function(){
     console.log("run")
  },
  clothes:[
    't-shirt',
    'pans',
    'shoes'
  ],
  child:{
    name:'tom',
    age:6
  }
}

//一级浅拷贝 
// const shallowCopy =(obj) => {
//   var newObj = {}
//   for (var prop in obj) {
//     if (src.hasOwnProperty(prop)) {
//       newObj[prop] = src[prop]
//     }
//   }
//   return newObj
// }


//深拷贝(一)
// date不能拷贝,循环属性没有预警
//此题目不可以使用json 转换,因为json无法转换 Date 对象
const deepCP1=(ob)=>{
  
if((typeof ob) != 'object' ){
   return ob
}
var newObj={}
 //遍历属性
for(var key in ob){
   if((typeof ob[key]) == 'object'){
      newObj[key] = deepCP1(ob[key])
     if(ob[key] instanceof Array){
         var newArray=[]
         //数组里如果有对象
         for(var o of ob[key]){
           newArray.push(deepCP1(o))
         }
         newObj[key]=newArray
      }
     if(ob[key] instanceof Date){
         newObj[key]=ob[key]
      }
   }else{
      newObj[key] = ob[key]
   }
 }
  return newObj
}

var newPerson=deepCP1(person)
person.age=16
person.run=function(){
  console.log("new run")
}
newPerson.child.age=15
// 删除某个元素
newPerson.clothes.splice(0,1)
newPerson.name="yuni"
console.log(person)
console.log(newPerson)

//深拷贝 (二) json方法
// const deepCP2=(obj)=>{
//   var s=JSON.stringify(obj)
//   var newObj=JSON.parse(s)
//   return newObj
// }
// var newP=deepCP2(person)
// person.name="greet"
// console.log(newP)


console.log("测试function的问题---->")
var a={
  name:"2",
  run:function(){
    console.log(this.name)
  },
  o:{
    name:"1111"
  }
}
b={}
b.run=a.run
b.o=a.o
b.name=a.name
a.name="3"
a.o.name="2222"

a.run()
b.run()
// var t=typeof b.run
// var r= b.run instanceof Object
// console.log(r)
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console