esprima - Javascript Object from External file, program -
i confused javascript's object system. know considered object in javascript in code of esprima, don't see statement declare project accessed esrpima following line: (https://github.com/ariya/esprima/blob/master/esprima.js)
var syntax = esprima.parse(text);
my question how , define esprima.parse(text)
in javascript can exported external package , accessed object name. know how define object object = {a: "b"}; can't find way figure out. please me!
(function (root, factory) { 'use strict'; // universal module definition (umd) support amd, commonjs/node.js, // rhino, , plain browser loading. if (typeof define === 'function' && define.amd) { define(['exports'], factory); } else if (typeof exports !== 'undefined') { factory(exports); } else { factory((root.esprima = {})); } }(this, function (exports) { 'use strict'; var token, tokenname, ...
that's because doesn't. variable name, esprima
, comes code includes esprima. example:
var esprima = require('esprima'); esprima.parse(text);
you give variable other name:
var foo = require('esprima'); foo.parse(text);
all the esprima.js
file define object exported. not dictate name of variable object assigned eventually.
if script loaded in browser, define esprima
explicitly. can see in line 55:
factory((root.esprima = {}));
this creates object , assigns root.esprima
. it's function call, object passed factory
, function defined in 57, accept parameter exports
. code assigns properties to.
Comments
Post a Comment