xuyingjie / xuyingjie.github.io

0 stars 0 forks source link

Object.observe() #1

Open xuyingjie opened 9 years ago

xuyingjie commented 9 years ago

ES7

Example:

var object = {};
Object.observe(object, function(changeRecords) {
  changeRecords.forEach(function(cr) {
    console.log(cr.name + ' ' + cr.type);
  });
});

object.p1 = 'Property 1';
object.p2 = 'Property 2';
object.p2 = 'Property II';
delete object.p1;
xuyingjie commented 9 years ago

使用Object.observe实现简单的双向绑定: http://zhuanlan.zhihu.com/FrontendMagazine/20047033