Track whether object changed

前端 未结 5 467
感情败类
感情败类 2021-01-12 23:33
// A simple Javascript Object / String
var object = \"hello\";

// Imagine a button in the DOM, and if it\'s clicked the object value will change
document.getElement         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-13 00:24

    Javascript does not allow you to set programmatic watchpoints/events on arbitrary objects/variables.

    You can use encapsulation to hide individual values inside the object from the outside world, allowing them to be modified only through dedicated "setter" functions that have the side-effects you desire.

提交回复
热议问题