我在Javascript中有以下内容:
var chartOptions = { chartType: settings.chartType, } chartOptions.func = function(chart) { chartOptions.fullChart = chart; }
一切正常.
但是我想把它改成TypeScript并且是新的,我不确定如何做到这一点.请有人帮忙吗?例如,'func'没有符号,'fullChart'没有符号,那么这怎么会在Javascript中起作用?
您可以修改代码,将属性添加到chartOptions
:
var chartOptions = { chartType: settings.chartType, func: null, fullChart: null } chartOptions.func = function(chart) { chartOptions.fullChart = chart; }
如何将代码转换为类?它更像TypeScript-y :)
class ChartOptions { public chartType; public fullChart; public func(chart: any) { this.fullChart = chart } } let chart = {}; let chartOptions = new ChartOptions(); chartOptions.func(chart);