javascript - RequireJS and TypeScript Class - Cannot call function externally -
i having tough figuring out how mix requirejs , typescript. compiling typescript amd option. problem is, function declared within exported class classified "prototype". normal?
modalhelper.ts:
export class modalhelper { saysomething = (something: string) => { alert(something); } }
compiled modalhelper.js:
define(["require", "exports"], function (require, exports) { var modalhelper = (function () { function modalhelper() { this.saysomething = function (something) { alert(something); }; } return modalhelper; })(); exports.modalhelper = modalhelper; });
create.ts , create.js (module marked required):
require(["jquery", "shared/modalhelper"], function ($, modal) { $(function () { modal.modalhelper.saysomething("hi"); }); });
why not able call function? debugging, see module being added via requirejs.
imo classes in typescript should used if need multiple instances data associated each instance. helper bunch of static methods. therefore suggest use module instead (untested):
shared/modalhelper.ts
module modalhelper { export function saysomething(something: string) { alert(something); } } export = modalhelper
create.ts
import modalhelper = require("./shared/modalhelper"); module create { modalhelper.saysomething("hello"); }
Comments
Post a Comment