简体   繁体   English

无法定义属性“ _getObservable”:对象不可扩展

[英]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.

相关问题 无法添加属性“X”,对象不可扩展 angular 9 - Cannot add property "X", object is not extensible angular 9 TypeError:无法添加属性 0,object 不可扩展 - TypeError: Cannot add property 0, object is not extensible React:无法添加属性“X”,对象不可扩展 - React : cannot add property 'X', object is not extensible 未捕获的类型错误:无法定义属性“x”:对象不可扩展 - Uncaught TypeError: can't define property "x": Object is not extensible 类型错误:无法定义属性“当前”:Object 不可扩展 - TypeError: can't define property “current”: Object is not extensible 无法添加属性,在 React 组件中绑定 props 时对象不可扩展 - Cannot add property, object is not extensible when binding props in React component Jest TestEnvironment - 类型错误:接下来无法添加属性,object 不可扩展 - Jest TestEnvironment - TypeError: Cannot add property next, object is not extensible 未捕获的类型错误:无法添加属性 0,object 在 Array.push 不可扩展 - Uncaught TypeError: Cannot add property 0, object is not extensible at Array.push React App-TypeError:无法添加属性setState,对象不可扩展 - React App - TypeError: Cannot add property setState, object is not extensible 材料表类型错误:无法添加属性表数据,对象不可扩展 - Material-table TypeError: Cannot add property tableData, object is not extensible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM