Created
March 28, 2019 02:19
-
-
Save deleteman/b81d701fb8e0e666e8537a1ebad1bf53 to your computer and use it in GitHub Desktop.
tojson serialization
This file contains hidden or 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
let testObj = { | |
name: "Fernando", | |
age: 35, | |
speak: function() { | |
console.log("Hello world!") | |
}, | |
toJSON: function() { | |
console.log("toJSON called") | |
}, | |
address: undefined | |
} | |
let testObj2 = { | |
name: "Fernando", | |
age: 35, | |
speak: function() { | |
console.log("Hello world!") | |
}, | |
toJSON: function() { | |
console.log("toJSON called") | |
return '{ "name": "' + this.name + '", "age": ' + this.age + ' }' | |
}, | |
address: undefined | |
} | |
let serializedObj = JSON.stringify(testObj) | |
let serializedObj2 = JSON.stringify(testObj2) | |
testObj.speak() | |
console.log(serializedObj) | |
console.log(typeof serializedObj) | |
console.log(" - - - - - - - - - - - - - ") | |
console.log(serializedObj2) | |
console.log(typeof serializedObj2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment