需求: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;
2.1m questions
2.1m answers
60 comments
57.0k users