我了解如何使用Object.observe()
,Object.getNotifier(obj).notify
或Object.getNotifier(obj).performChange
,但我如何使用Object.deliverChangeRecords()
答案 0 :(得分:6)
Object.deliverChangeRecords的目的是获得同步传递 听取突变的功能。
http://www.danyow.net/object-deliverchangerecords/
这是一个运行示例,演示了包含和不包含deliverChangeRecords
的事件序列:
var output = document.getElementById('output');
function runTest(useDeliver) {
var obj = {};
output.textContent = '';
function handleChange(records) {
output.textContent += 'CHANGE DELIVERED\n';
}
Object.observe(obj, handleChange);
output.textContent += '1\n';
obj.a = 'b';
output.textContent += '2\n';
if (useDeliver) {
Object.deliverChangeRecords(handleChange);
}
output.textContent += '3\n';
}

<button onclick="runTest(true)">With deliverChangeRecords</button>
<button onclick="runTest(false)">Without deliverChangeRecords</button>
<pre id="output"></pre>
&#13;