使用TypeScript简化JavaScript代码
我想知道是否有办法简化以下代码:使用TypeScript简化JavaScript代码,javascript,typescript,ecmascript-6,Javascript,Typescript,Ecmascript 6,我想知道是否有办法简化以下代码: this._session = AmberFile.session; this._sessionPath = AmberFile.sessionPath; this._sessionDevice = AmberFile.sessionDevice; this._ssconfig = AmberFile.ssconfig; 我尝试使用TypeScript/ES6,但它似乎没有更干净的代码: const {session, sessionPath, session
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
})
Object.assign方法用于将所有可枚举自身属性的值从一个或多个源对象复制到目标对象。它将返回目标对象
阅读更多:
对。有:
Object.assign(this,{
_session:AmberFile.session,
_sessionPath:AmberFile.sessionPath
})
Object.assign方法用于将所有可枚举自身属性的值从一个或多个源对象复制到目标对象。它将返回目标对象
阅读更多:
看
见谢谢。我修好了,谢谢。我修好了。