javascript - How to access the functions and objects requireJS module -
i'm working on scripts site uses requirejs , weird syntax i've never seen before.
define("app/models/usermodel", ["backbone", "lang/lang"], function (e, t) { var n = e.model.extend({ defaults: { item: "", these: "", arent: "", important: "en", relationship: 0, _position: { c: 0, r: 0 } }, haspermission: function (e) { return this.get("permission") >= e }, gettotalpoints: function () { return this.get("somestuff") } });
i've used require(["app/models/usermodel"]) load module , require("app/models/usermodel").default try , load object , same method try , use functions comes saying don't exist. i've been able access functions in model same way of others doesn't work.
aside wondering if var n = e.model.extend has it. can't understand function of is.
the structure required asynchronous module loading work. requirejs module constructed within function called define
; function supposed return
public interface of module. in case, need like:
define("app/models/usermodel", ["backbone", "lang/lang"], function (backbone, lang) { var mymodel = backbone.model.extend({ defaults: { item: "", these: "", arent: "", important: "en", relationship: 0, _position: { c: 0, r: 0 } }, haspermission: function (e) { return this.get("permission") >= e }, gettotalpoints: function () { return this.get("somestuff") } }); // return created model object // accessible require("app/models/usermodel").default_ return { default_: mymodel } });
(beware not familiar backbone, though). also, guess module using minified , beautified, because variable names 1 letter long, , not mnemonic? also, default
keyword, use within switch
statements, , not valid variable name @ all.
Comments
Post a Comment