[英]Cannot define property '_getObservable': object is not extensible
I'm facing an issue and I'm not sure why. 我面临一个问题,我不确定为什么。 I'm setting a StorageFile as a property of a javascript object: 我将StorageFile设置为javascript对象的属性:
var myFile = MethodThatReturnsAFile();
var obj = { file: myFile };
The problem comes when I need to 'clone' that object. 问题出在我需要“克隆”该对象时。 Based on a lot of SO answers on the matter I've come to use this method for cloning my objects: 基于很多关于此问题的答案,我开始使用此方法克隆对象:
for (var pty in obj)
if (obj.hasOwnProperty(pty) && target[pty] !== obj[pty])
target[pty] = obj[pty];
Where obj
is my current object and target
is the object I want to create, in my case var target = {}
. 其中obj
是我当前的对象,而target
是我要创建的对象,在我的情况下是var target = {}
。
It works fine 'almost' everytime, expect when obj
has a StorageFile
in one of its properties. 每当obj
在其属性之一中具有StorageFile
时,它几乎每次都能正常工作。 (I get the message from the subject) (我从主题中得到消息)
I unserstand Storagefile
is sealed and can't be extended, but why is who ( WinJS?
) trying to extend it? 我无法理解Storagefile
是密封的,无法扩展,但是为什么有人( WinJS?
)试图扩展它? Should I change my clone
method or should I not have StorageFile
as property values? 我应该更改clone
方法还是不应该将StorageFile
作为属性值?
JavaScript object properties may be not enumerable and hidden from 'for' or 'Object.keys' JavaScript对象属性可能无法枚举,并且对于'for'或'Object.keys'隐藏
Look defineProperty method https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty 查看defineProperty方法https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.