We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
undefined
任意 function
symbol 值
null
// 3.1 const obj = [undefined, ()=>{}, Symbol(foo)] const cloneObj = JSON.parse(JSON.stringify(obj)) // [null, null, null] // 3.2 const obj = { a: undefined, b: () => {}, c: Symbol('foo') } const cloneObj = JSON.parse(JSON.stringify(obj)) // {}
JSON.parse(undefined)
SyntaxError: "undefined" is not valid JSON
JSON.stringify(function(){}) // undefined JSON.stringify(undefined) // undefined
replacer
Date.toISOString()
NaN
Infinity
JSON.stringify(NaN) // 'null' JSON.stringify(Infinity) // 'null' JSON.stringify(null) // 'null'
structuredClone
https://developer.mozilla.org/zh-CN/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
function
const function Person() {} Person.prototype.a = 1 Person.prototype.foo = ()=>{} const p = new Person() const a = {p: p} // {p: Person} const cloneA = structuredClone(a) // {p:{}}
JavaScript 类型
Error 类型
仅支持以下 Error 类型:Error、EvalError、RangeError、ReferenceError、SyntaxError、TypeError、URIError(或其他会被设置为 Error 的)
如 lodash/deepClone
lodash/deepClone
The text was updated successfully, but these errors were encountered:
No branches or pull requests
1. JSON.parse(JSON.stringify())
undefined
,任意 function
,symbol 值
,在序列化的过程中,呈现以下两种情况:3.1 数组中,转化成
null
3.2 非数组中(对象属性值时),忽略
任意 function
或undefined
被单独转化时,会返回undefined
,但是JSON.parse(undefined)
会抛错SyntaxError: "undefined" is not valid JSON
;replacer
参数中强制指定包含了它们;Date.toISOString()
),因此会被当做字符串处理;NaN
和Infinity
格式的数值及null
都会被当做null
;2.
structuredClone
function
不能被结构化克隆;2.1 结构化克隆支持的类型
JavaScript 类型
Error 类型
仅支持以下 Error 类型:Error、EvalError、RangeError、ReferenceError、SyntaxError、TypeError、URIError(或其他会被设置为 Error 的)
3. 自定义深拷贝
4. 其他外部库
如
lodash/deepClone
The text was updated successfully, but these errors were encountered: