需求:object.array[index] = value 时调用 setter
object.array[index] = value
利用Proxy:
Proxy
var arr = [] var proxyArr = new Proxy(arr, { set: function(target, key, value) { // do something console.log(`key=${key}, value=${value}`); target[key] = value; } }); proxyArr[0] = 12;
1.4m articles
1.4m replys
5 comments
57.0k users