我有这个Node类:
export const symbols = {
parent: Symbol('@xml.js.parent'),
};
export class Node {
[key: string]: any;
constructor(parent: Node, name: string) {
Object.defineProperty(this, symbols.parent, {
value: parent,
writable: true,
enumerable: false
});
}
}
我创建了一个新节点,然后尝试删除其中一个符号键:
/Users/alexamil/WebstormProjects/oresoftware/xml.json/dist/index.js:141
delete self.currentNode[exports.symbols.parent];
^
TypeError: Cannot delete property 'Symbol(@xml.js.parent)' of #<Node>
at ReadStream.<anonymous> (/Users/alexamil/WebstormProjects/oresoftware/xml.json/dist/index.js:141:61)
at ReadStream.emit (events.js:159:13)
at addChunk (_stream_readable.js:265:12)
at readableAddChunk (_stream_readable.js:248:13)
at ReadStream.Readable.push (_stream_readable.js:209:10)
at onread (fs.js:2115:12)
at FSReqWrap.wrapper [as oncomplete] (fs.js:676:17)
被这条线绊倒:
delete self.currentNode[exports.symbols.parent];
有谁知道为什么我不能删除该属性?
由于符号道具的writable
设置为true,因此它似乎应该可以工作,但是idk。
答案 0 :(得分:1)
看起来我需要将configurable
道具设置为true
Object.defineProperty(this, symbols.parent, {
value: parent,
writable: true,
enumerable: false,
configurable: true
});