有没有人一起来建设一个社交平台

11,598 阅读1分钟

image.png

有的可以私聊我

我的想法是这样的

我可以将你加入我的项目(打算是开源项目)

有后端同志?研究 以太坊,或者 马蹄莲上面的

github链接

JSON.parse,JSON.stringify问题记录

在做列设置组件的时候,发现深复制组件传进来的参数,会产生函数,属性为 undefined 的key,Date 日期会丢失问题

例如以下代码

localStorage.setItem(`${props.page}_FB_COLUMNS`, JSON.stringify(draggableArr.value))

如果 draggableArr.value 这个数组对象里面存在函数,属性为 undefined,Date 日期会丢失

可以参考这个链接

juejin.cn/post/691750…

  1. 转存失败,建议直接上传图片文件

    转存失败,建议直接上传图片文件

对比原有的对象,我们可以知道:

  1. 不会拷贝对象上的 value 值为 undefined 和 函数的键值对

  2. NaN,无穷大,无穷小会被转为 null

let Ken = function() {
    this.name = "Ken"
}

Ken.prototype.walk = function() {
    console.log("walk")
}

let KenNaNa = function() {
    Ken.call(this, arguments)
    this.name = "KenNaNa"
}

let tempFunc = function() {}
tempFunc.prototype = Ken.prototype
KenNaNa.prototype = new tempFunc()
KenNaNa.prototype.age = "18"
KenNaNa.prototype.run = function() {
    console.log("run")
}

Object.defineProperty(KenNaNa.prototype, "contructor", {
    value: KenNaNa,
    enumerable:false
})

let kenNaNa = new KenNaNa()
let copyKenNaNa = JSON.parse(JSON.stringify(kenNaNa))

/**
 Ken {age: "18", run: ƒ, contructor: ƒ}
 * */ 
console.log(copyKenNaNa.constructor); // ƒ Object() { [native code]}
console.log(copyKenNaNa.age) // undefined
console.log(copyKenNaNa.run()) // is not function
console.log(copyKenNaNa.walk()) // is not function 
console.log(copyKenNaNa.toString()) // "[object Object]"
  1. 取不到值为 undefined 的 key

  2. NaN 和 无穷大,无穷小转变为 null

  3. 取不到原型的内容

  4. date 对象转变为 date 字符串

Symbol() 会丢失

let cc = { name: Symbol(111111) }
let bbb = JSON.parse(JSON.stringify(cc))
console.log(bbb)