简体   繁体   中英

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:

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 = {} .
It works fine 'almost' everytime, expect when obj has a StorageFile in one of its properties. (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? Should I change my clone method or should I not have StorageFile as property values?

JavaScript object properties may be not enumerable and hidden from 'for' or 'Object.keys'

Look defineProperty method https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM