对象的克隆(clone)也叫拷贝、复制。我们都知道,对象在赋值的过程中其实是复制了该对象的引用地址,所以一方面改变,另一方也会跟着变。
'%3e%3cpath%20d='M624.68,512.43a16,16,0,0,1,0,22.63l-45.25,45.25a16,16,0,0,1-22.63-22.63l45.26-45.25a16,16,0,0,0,.19-22.43Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M602.25,490l-34.13-34.13h0L556.8,444.55a16,16,0,0,0-22.63,0l22.63-22.63a16,16,0,0,1,22.63,0l67.88,67.88a16,16,0,0,1,0,22.63l-22.63,22.63a16,16,0,0,0,0-22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpolygon%20points='219.66%2038.63%20219.66%2038.64%20208.34%2027.32%20219.66%2038.63'%20fill='%23fff'%20/%3e%3cpath%20d='M534.17,444.55a16,16,0,0,1,22.63,0l11.32,11.32-45.26,45.25L511.55,489.8a16,16,0,0,1,0-22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M466.29,557.68a16,16,0,0,1-22.62,0l-11.32-11.31,45.26-45.25,11.31,11.31a16,16,0,0,1,0,22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M443.67,557.68a16,16,0,0,0,22.62,0l-22.62,22.63a16,16,0,0,1-22.63,0l-67.88-67.88a16,16,0,0,1,0-22.63l22.62-22.63a16,16,0,0,0,0,22.63l22.63,22.63,33.94,33.94Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M421,421.92a16,16,0,0,1,22.63,22.63L398.41,489.8a16,16,0,0,0-.06,22.56L375.78,489.8a16,16,0,0,1,0-22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M398.35,512.36l.06.07L375.78,489.8Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3c/g%3e%3c/svg%3e)
当谈到继承时,JavaScript只有一种结构:对象。每个实例对象(object)都有一个私有属性__proto__指向它的构造函数的原型对象(prototype)
'%3e%3cpath%20d='M624.68,512.43a16,16,0,0,1,0,22.63l-45.25,45.25a16,16,0,0,1-22.63-22.63l45.26-45.25a16,16,0,0,0,.19-22.43Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M602.25,490l-34.13-34.13h0L556.8,444.55a16,16,0,0,0-22.63,0l22.63-22.63a16,16,0,0,1,22.63,0l67.88,67.88a16,16,0,0,1,0,22.63l-22.63,22.63a16,16,0,0,0,0-22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpolygon%20points='219.66%2038.63%20219.66%2038.64%20208.34%2027.32%20219.66%2038.63'%20fill='%23fff'%20/%3e%3cpath%20d='M534.17,444.55a16,16,0,0,1,22.63,0l11.32,11.32-45.26,45.25L511.55,489.8a16,16,0,0,1,0-22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M466.29,557.68a16,16,0,0,1-22.62,0l-11.32-11.31,45.26-45.25,11.31,11.31a16,16,0,0,1,0,22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M443.67,557.68a16,16,0,0,0,22.62,0l-22.62,22.63a16,16,0,0,1-22.63,0l-67.88-67.88a16,16,0,0,1,0-22.63l22.62-22.63a16,16,0,0,0,0,22.63l22.63,22.63,33.94,33.94Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M421,421.92a16,16,0,0,1,22.63,22.63L398.41,489.8a16,16,0,0,0-.06,22.56L375.78,489.8a16,16,0,0,1,0-22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M398.35,512.36l.06.07L375.78,489.8Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3c/g%3e%3c/svg%3e)
在AJAX兴起以前,很多人写JS可以说都是毫无章法可言的,基本上是想到什么就写什么,就是一个接一个的函数function,遇到重复的还得 copy,如果一不小心函数重名了,还真不知道从何开始查找错误
'%3e%3cpath%20d='M624.68,512.43a16,16,0,0,1,0,22.63l-45.25,45.25a16,16,0,0,1-22.63-22.63l45.26-45.25a16,16,0,0,0,.19-22.43Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M602.25,490l-34.13-34.13h0L556.8,444.55a16,16,0,0,0-22.63,0l22.63-22.63a16,16,0,0,1,22.63,0l67.88,67.88a16,16,0,0,1,0,22.63l-22.63,22.63a16,16,0,0,0,0-22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpolygon%20points='219.66%2038.63%20219.66%2038.64%20208.34%2027.32%20219.66%2038.63'%20fill='%23fff'%20/%3e%3cpath%20d='M534.17,444.55a16,16,0,0,1,22.63,0l11.32,11.32-45.26,45.25L511.55,489.8a16,16,0,0,1,0-22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M466.29,557.68a16,16,0,0,1-22.62,0l-11.32-11.31,45.26-45.25,11.31,11.31a16,16,0,0,1,0,22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M443.67,557.68a16,16,0,0,0,22.62,0l-22.62,22.63a16,16,0,0,1-22.63,0l-67.88-67.88a16,16,0,0,1,0-22.63l22.62-22.63a16,16,0,0,0,0,22.63l22.63,22.63,33.94,33.94Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M421,421.92a16,16,0,0,1,22.63,22.63L398.41,489.8a16,16,0,0,0-.06,22.56L375.78,489.8a16,16,0,0,1,0-22.63Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3cpath%20d='M398.35,512.36l.06.07L375.78,489.8Z'%20transform='translate(-348.47%20-417.23)'%20fill='%23fff'%20/%3e%3c/g%3e%3c/svg%3e)