typescript - Unexpected token; 'constructor, function, accessor or variable' expected -
sorry newbie question, trying learn type script.
i have following class
class indexgridfunctions { //error on var var blocksperrow: (windowwidth:number)=>number = function (windowwidth) { return math.floor(windowwidth / 12); }; var blockspercolumn: (windowheight: number) => number = function (windowheight) { return math.floor(windowheight / 17); }; shirtstodisplay: () => number = function () { return blocksperrow * blockspercolumn; }; }
i getting error @ first var. error "unexpected token; 'constructor, function, accessor or variable' expected".
what doing wrong?
tia
don't use var
. invalid syntax within class body. fixed code :
class indexgridfunctions { blocksperrow: (windowwidth: number) => number = function (windowwidth) { return math.floor(windowwidth / 12); }; blockspercolumn: (windowheight: number) => number = function (windowheight) { return math.floor(windowheight / 17); }; shirtstodisplay: () => number = () => { return this.blocksperrow(123) * this.blockspercolumn(123); }; }
i did other fixes code in code ive presented:
blocksperrow
,blockspercolumn
not defined. usethis.
. , function call(123)
.- prefer
arrow ()=>
onfunction
if going use=
(more https://www.youtube.com/watch?v=tvocucbcupa)
Comments
Post a Comment