Skip to content

Instantly share code, notes, and snippets.

@krfong916
Created December 16, 2019 22:59
Show Gist options
  • Save krfong916/b18d4c8341dbab233d82461fd44e23bb to your computer and use it in GitHub Desktop.
Save krfong916/b18d4c8341dbab233d82461fd44e23bb to your computer and use it in GitHub Desktop.
var dfs = {
result: function(){
return {
test: []
}
},
setup: function() {
var test1 = this.result()
test1.test.push('a');
this.modify(test1)
return test1;
},
modify: function(test1) {
test1.test.push('zzz')
}
}
var obj1 = dfs.setup()
var obj2 = dfs.setup()
obj1.test.push(1)
obj2.test.push(2)
console.log('DFS1 obj1:',obj1) // DFS1 obj1: Array[a, 1]
console.log('DFS1 obj2:',obj2) // DFS1 obj2: Array[a, 2]
// var dfs2 = {
// result1: {
// test1: []
// },
// setup: function() {
// this.result1.test1.push('b');
// return this.result1;
// }
// }
// var obj3 = dfs2.setup()
// var obj4 = dfs2.setup()
// obj3.test1.push(1)
// obj4.test1.push(2)
// console.log('DFS2 obj3:',obj3) // DFS2 obj3: Array[b, 1]
// console.log('DFS2 obj4:',obj4) // DFS2 obj3: Array[b, 1, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment