function copyDom() {
Copy.copyDom(getEl('#textarea')[0])
alert('Copy success!')
}
The command `copy` can only works in click event triggered by users
Image copy may not always works, it is under the influence of computer system, domain (such as: github.io -> https://livelybone.github.io/common/images/natuto.jpeg), url extension and something else
function copyImg() {
Copy.copyDom(getEl('#img')[0])
alert('Copy success!')
}
function copyText() {
Copy.copyText('My name is livelybone')
.then(() => alert('Copy success!'))
.catch(alert)
}
Can not copy object that has circular structure. See results in console
!(function() {
var obj = {
name: 'livelybone',
age: 26,
}
var obj1 = Copy.objectSimpleCopy(obj)
console.log('---- objectSimpleCopy ----')
console.log('> obj: ', obj)
console.log('> obj1: ', obj1)
console.log('> whether obj is equal to obj1: ', obj === obj1)
})()
Can copy object that has circular structure. See results in console
!(function() {
var obj = {
name: 'livelybone',
age: 26,
}
obj.quote = obj
var obj1 = Copy.objectDeepCopy(obj)
console.log('---- objectDeepCopy ----')
console.log('> obj: ', obj)
console.log('> obj1: ', obj1)
console.log('> whether obj is equal to obj1: ', obj === obj1)
console.log('> whether obj.quote is equal to obj1.quote: ', obj.quote === obj1.quote)
console.log('> whether obj1 is equal to obj1.quote: ', obj1.quote === obj1)
})()
See results in console
!(function() {
var obj = {
name: 'livelybone',
age: 26,
bwh: [2, 1, 3],
lover: 'Yanci',
}
var obj1 = {
name: 'Yanci',
age: 26,
bwh: [1, 2, 3],
height: 160,
lover: 'livelybone',
}
var obj2 = Copy.objectDeepMerge({}, obj, obj1)
console.log('---- objectDeepMerge ----')
console.log('> obj: ', obj)
console.log('> obj1: ', obj1)
console.log('> obj2: ', obj2)
})()