简体   繁体   English

前端开发人员面临的一个有趣挑战

[英]An interesting challenge for frontend developer

Found an interesting problem that I can't solve. 发现了一个我无法解决的有趣问题。

1 condition. 1个条件。 Only json can be changed! 只能更改json!

I can't fulfill one condition: data.hasOwnProperty("\\u{0030}") 我无法满足以下条件: data.hasOwnProperty("\\u{0030}")

class JobSeeker {

    get data() {
            return '{"\\\\u{0030}": {}}';
    }

    }

    let data;
    console.assert(
        typeof (data = JSON.parse(new JobSeeker().data)) === "object"
        && data.hasOwnProperty("\u{0030}")
        && typeof Object.values(data)[0] === "object"
        && Boolean(data[+false]) === false
    );

What do you think will be the right json to suit all conditions? 您认为适合所有条件的json是什么?

It works if you change the data getter to this: 如果您将data更改为此,它将起作用:

get data() {
  return '{"\\u0030": null}';
}

That passes the first test because a valid JSON string is returned. 通过第一个测试,因为返回了有效的JSON字符串。 The second test passes because "0" is the name of the only property in the object. 第二个测试通过,因为“ 0”是对象中唯一属性的名称。 The third test passes because typeof null is "object" . 第三次测试通过,因为typeof null"object" The fourth test passes because Boolean(null) is false . 第四个测试通过,因为Boolean(null)false

I think it would also work if you change \\\0 to just plain 0 . 我认为,如果将\\\0更改为纯0它也将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM