__proto__, when will it be gone? Alternatives?

前端 未结 3 2004
-上瘾入骨i
-上瘾入骨i 2020-12-01 11:22

Mozilla claimed it would remove __proto__ a while back (~2008) and it is still in the browser. Is it still going to be deprecated? It works in Opera, (Safari I think) and Ch

3条回答
  •  没有蜡笔的小新
    2020-12-01 11:45

    I think the actual point Mozilla wanted to make is that it's nonstandard, so the implementors would be perfectly within their rights removing it.

    The cleaner way to do prototype chains is Object.create. The equivalent of your code, to create an object a with the prototype {'a': 'test'}, is:

    a = Object.create({'a':'test'})
    

    There are also shims to mimic this function in browsers that don't support it, if you ever need to work with one, which is another advantage over directly messing around with __proto__.

提交回复
热议问题