diff --git a/test/test.ts b/test/test.ts index c5b0815..628ef63 100644 --- a/test/test.ts +++ b/test/test.ts @@ -26,8 +26,8 @@ tap.test('should create a folded object', async () => { }); tap.test('should enfold from object', async () => { - mySomeClass.enfoldFromObject({ thisis: 'test2' }); - expect(mySomeClass) + const mySomeClass2 = SomeClass.enfoldFromObject({ thisis: 'test2' }); + expect(mySomeClass2) .property('thisis') .to.equal('test2'); }); diff --git a/ts/index.ts b/ts/index.ts index 13ccec9..58f7359 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -14,6 +14,19 @@ export class Smartjson { objArg = JSON.parse(bufferedJson); return plugins.stableJson(objArg, optionsArg); } + + /** + * enfolds data from an object + */ + public static enfoldFromObject(objectArg) { + const newInstance = new this(); + for (const keyName in objectArg) { + if (newInstance.saveableProperties.indexOf(keyName) !== -1) { + newInstance[keyName] = objectArg[keyName]; + } + } + return newInstance; + } // ======== // INSTANCE @@ -31,17 +44,6 @@ export class Smartjson { } return newFoldedObject; } - - /** - * enfolds data from an object - */ - public enfoldFromObject(objectArg) { - for (const keyName in objectArg) { - if (this.saveableProperties.indexOf(keyName) !== -1) { - this[keyName] = objectArg[keyName]; - } - } - } } /**