カスタムオブジェクトを作成するときに、ネイティブの 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;
};