首页 > ES7中的Object.observe被移除了吗?

ES7中的Object.observe被移除了吗?

前几天在知乎上看到过一篇文章提起过,但是现在搜索不到,隐约有点印象。

想问问大家这个是干什么用的,究竟被移除了吗?如果是的话,为什么呢。


现在immutable的对象这么盛行,要observe没什么卵用。移除是必然的。


通过 Object.observe 能直接知道标准对象的变化或者说对该对象的操作,下面是官方的例子:

var records;
function observer(recs) {
  records = recs;
}

var obj = { id: 1 };
Object.observe(obj, observer);

obj.a = 'b';
obj.id++;
Object.defineProperty(obj, 'a', { enumerable: false });
delete obj.a;
Object.preventExtensions(obj);

Object.deliverChangeRecords(observer);
assertChangesAre(records, [
  { object: obj, type: 'add', name: 'a' },
  { object: obj, type: 'update', name: 'id', oldValue: 1 },
  { object: obj, type: 'reconfigure', name: 'a' },
  { object: obj, type: 'delete', name: 'a', oldValue: 'b' },
  { object: obj, type: 'preventExtensions', }
]);

pS:现在ES7只是提案而已,并不是正式标准
pS2:没仔细看,那个链接的草案已经不更新了,这个方法是要弃用了

After much discussion with the parties involved, I plan to withdraw
the Object.observe proposal from TC39 (where it currently sits at
stage 2 in the ES spec process), and hope to remove support from V8 by
the end of the year (the feature is used on 0.0169% of Chrome
pageviews, according to chromestatus.com).

MDN Object.observe
ECMAScript Object.observe 规范草案
Object.observe Discuss
一则报道:JavaScript upgrade will nix object observation feature


是从标准中移除了。


嗯,已经确定从标准提议案中消除了。

【热门文章】
【热门文章】