在创建自定义对象时,给它提供覆盖本机 js 函数的方法(在我目前的情况下是“读取”、“写入”和“保存”)是否安全?
有问题的对象永远不必写入 DOM(或以其他方式使用它将丢失的函数);这些方法名称很理想,所以我很好奇,然后惊讶地发现很难找到一个明确的答案。下面的例子。谢谢。
/**
* Ticket class
* @param category
* @param issuedBy
* @param reissuable If true, lock cannot be overridden by the same method that locked it
* @returns {Ticket}
* @constructor
*/
Ticket = function (category, issuedBy, reissuable) {
//properties
this.id = Date.now().toString();
this.category = category;
this.resolved = false;
this.issuingMethod = issuedBy;
this.reissuable = reissuable === true;
this.data = {};
//methods
this.resolve = function () { return this.resolved = true;};
this.read = function (dataPath) { // find dataPath in this.data }
this.write = function (dataPath, value) { // add value to dataPath of this.data}
return this;
};