gpt4 book ai didi

javascript - 使用 TypeScript 简化 JavaScript 代码

转载 作者:行者123 更新时间:2023-11-30 09:17:22 24 4
gpt4 key购买 nike

我想知道是否有办法简化以下代码:

this._session = AmberFile.session;
this._sessionPath = AmberFile.sessionPath;
this._sessionDevice = AmberFile.sessionDevice;
this._ssconfig = AmberFile.ssconfig;

我尝试使用 TypeScript/ES6,但看起来它没有更清晰的代码:

const {session, sessionPath, sessionDevice, ssconfig) = AmberFile
this._session = session;
this._sessionPath = sessionPath;
this._sessionDevice = session;
this._ssconfig = sessionPath;

let context: any = {
sessionPath: this._sessionPath,
session: this._session,
sessionDevice: this._sessionDevice
}

最佳答案

是的。有:

 Object.assign(this,{
_session:AmberFile.session,
_sessionPath:AmberFile.sessionPath
})

The Object.assign() method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object.

阅读更多:

关于javascript - 使用 TypeScript 简化 JavaScript 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54118406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com