This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
First install and run ganache. | |
> npm install ganache --global | |
> execute this code https://gist.github.com/bertolo1988/096d436f072d2513eb4ff1cd83201c47 | |
**/ | |
const Web3EthAccounts = require('web3-eth-accounts'); | |
const PORT = 61063; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ganache = require('ganache'); | |
const options = {}; | |
const server = ganache.server(options); | |
const PORT = 0; // 0 means any available port | |
server.listen(PORT, async (err) => { | |
if (err) throw err; | |
console.log(`ganache listening on port ${server.address().port}...`); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Method name | clone is callable | typeof is function | enumerable properties | name | prototype | constructor | clone is independent | |
---|---|---|---|---|---|---|---|---|
cloneJSON | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
structuredClone | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
underscoreContribClone | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | |
cloneNemisj | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | |
cloneTrincot | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | |
cloneKoolDandy | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | |
cloneRfdc | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | |
justClone | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | |
cloneDeep | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Method name | should clone an object with circular reference to an element of the array | |
---|---|---|
cloneJSON | ❌ | |
structuredClone | ✅ | |
underscoreContribClone | ❌ | |
cloneNemisj | ❌ | |
cloneTrincot | ✅ | |
cloneKoolDandy | ❌ | |
cloneRfdc | ✅ | |
justClone | ❌ | |
cloneDeep | ❌ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Method name | __proto__ by referencing | clones the __proto__ | non enumerable properties in the prototype | |
---|---|---|---|---|
cloneJSON | ❌ | ❌ | ❌ | |
structuredClone | ❌ | ✅ | ❌ | |
underscoreContribClone | ❌ | ❌ | ❌ | |
cloneNemisj | ❌ | ❌ | ❌ | |
cloneTrincot | ❌ | ❌ | ❌ | |
cloneKoolDandy | ❌ | ❌ | ❌ | |
cloneRfdc | ❌ | ❌ | ❌ | |
justClone | ❌ | ❌ | ❌ | |
cloneDeep | ✅ | ❌ | ✅ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Method name | frozen | sealed | non extensible | |
---|---|---|---|---|
cloneJSON | ❌ | ❌ | ❌ | |
structuredClone | ❌ | ❌ | ❌ | |
underscoreContribClone | ❌ | ❌ | ❌ | |
cloneNemisj | ❌ | ❌ | ❌ | |
cloneTrincot | ❌ | ❌ | ❌ | |
cloneKoolDandy | ❌ | ❌ | ❌ | |
cloneRfdc | ❌ | ❌ | ❌ | |
justClone | ❌ | ❌ | ❌ | |
cloneDeep | ❌ | ❌ | ❌ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Method name | getter | setter | enumerable | non enumerable | enumerable and writable | non enumerable non writable and configurable | non enumerable writable and non configurable | non enumerable non writable and non configurable | own symbol | |
---|---|---|---|---|---|---|---|---|---|---|
cloneJSON | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
structuredClone | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
underscoreContribClone | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
cloneNemisj | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
cloneTrincot | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
cloneKoolDandy | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
cloneRfdc | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
justClone | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
cloneDeep | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Method name | shallow object | non shallow object | circular references | typeof | constructor | |
---|---|---|---|---|---|---|
cloneJSON | ✅ | ✅ | ❌ | ✅ | ✅ | |
structuredClone | ✅ | ✅ | ✅ | ✅ | ✅ | |
underscoreContribClone | ✅ | ✅ | ❌ | ✅ | ✅ | |
cloneNemisj | ✅ | ✅ | ❌ | ✅ | ✅ | |
cloneTrincot | ✅ | ✅ | ✅ | ✅ | ✅ | |
cloneKoolDandy | ✅ | ✅ | ❌ | ✅ | ✅ | |
cloneRfdc | ✅ | ✅ | ❌ | ✅ | ✅ | |
justClone | ✅ | ✅ | ❌ | ✅ | ✅ | |
cloneDeep | ✅ | ✅ | ❌ | ✅ | ✅ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Method name | string | number | boolean | undefined | null | Symbol | BigInt | |
---|---|---|---|---|---|---|---|---|
cloneJSON | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | |
structuredClone | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | |
underscoreContribClone | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
cloneNemisj | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
cloneTrincot | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
cloneKoolDandy | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
cloneRfdc | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
justClone | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
cloneDeep | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How to clone a javascript object without just referencing the prototype | |
const assert = require('node:assert') | |
const input = { a: 1 } | |
// every prototype is an object with normal property descriptors | |
const prototypeDescriptors = Object.getOwnPropertyDescriptors( | |
Object.getPrototypeOf(input) | |
) |
NewerOlder