javascript - TypeScript class function not available -


i'm trying call instance method of typescript class (in asp.net mvc project). however, @ runtime exceptions 0x800a01b6 - javascript runtime error: object doesn't support property or method 'checkstring'.

i copied generated javascript in jsfiddle method seems work.
i'm not javascript guy, appreciated!

things have tried far:

  1. different browsers (chrome: uncaught typeerror: undefined not function, ff: typeerror: this.checkstring not function)
  2. clearing browser caches
  3. deleting temporary files of iis express
  4. cleaning , rebuilding solution
  5. not using private modifier
  6. starting project on machine
  7. replacing underscore.js call dummy verfiy that's not problem
  8. checked instance members correctly set

this typescript code:

class formdata {     blogname: string;     cachetimeout: number;     copyrightholder: string;     navbartitle: string;     markdownextra: boolean;     markdownsanitize: boolean;     ratingactive: boolean;     htmleditor: boolean;      constructor(blogname: string, cachetimeout: number, copyrightholder: string, navbartitle: string, markdownextra: boolean, markdownsanitize: boolean, ratingactive: boolean, htmleditor: boolean) {         this.blogname = blogname;         this.cachetimeout = cachetimeout;         this.copyrightholder = copyrightholder;         this.navbartitle = navbartitle;         this.markdownextra = markdownextra;         this.markdownsanitize = markdownsanitize;         this.ratingactive = ratingactive;         this.htmleditor = htmleditor;     }      private checkstring(value: string): boolean {         return _.isstring(value) && value !== '';     }      validate(): boolean {         return (this.checkstring(this.blogname) && this.checkstring(this.copyrightholder) && this.checkstring(this.navbartitle) && _.isnumber(this.cachetimeout) && !_.isnull(this.markdownextra) && !_.isnull(this.markdownsanitize) && !_.isnull(this.ratingactive));     }        }  //i'm calling validate function (from within same module) var form = getformdata(); //returns formdata instance if (!form.validate()) {     //foo } 

and here generated javascript:

var formdata = (function () {     function formdata(blogname, cachetimeout, copyrightholder, navbartitle, markdownextra, markdownsanitize, ratingactive, htmleditor) {         this.blogname = blogname;         this.cachetimeout = cachetimeout;         this.copyrightholder = copyrightholder;         this.navbartitle = navbartitle;         this.markdownextra = markdownextra;         this.markdownsanitize = markdownsanitize;         this.ratingactive = ratingactive;         this.htmleditor = htmleditor;     }     formdata.prototype.checkstring = function (value) {         return _.isstring(value) && value !== '';     };      formdata.prototype.validate = function () {         return (this.checkstring(this.blogname) && this.checkstring(this.copyrightholder) && this.checkstring(this.navbartitle) && _.isnumber(this.cachetimeout) && !_.isnull(this.markdownextra) && !_.isnull(this.markdownsanitize) && !_.isnull(this.ratingactive));     };     return formdata; })(); 

this because of wrong this @ runtime. can use lambda function ()=>{} instead of function make sure this lexically scoped in generated javascript:

validate = (): boolean => {         return (this.checkstring(this.blogname) && this.checkstring(this.copyrightholder) && this.checkstring(this.navbartitle) && _.isnumber(this.cachetimeout) && !_.isnull(this.markdownextra) && !_.isnull(this.markdownsanitize) && !_.isnull(this.ratingactive));     }  

please search this means in javascript , typescript learn more.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -