如何在客户端脚本中访问由Browerify制作的JS文件中使用Prototype制作的JS类方法?

时间:2017-07-20 13:31:09

标签: javascript node.js prototype prototypejs browserify

节点Js代码(Factory.js)

require("prototype");
var Factory= Class.create({

initialize: function (configuration) {
    // init code
},
createConnector : function (configuration) {        
    return 'Factory string';
}    
});

if ('undefined' !== typeof module) {
    module.exports = Factory;
}

另一个文件index.js需要此模块,它基本上需要它并将其设置在它的导出对象中

 var Factory= required("Factory");
 module.exports = {Factory: Factory};

使用Browserify(sdk.js)创建的JS文件的代码结构

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof 
require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var 
f=new Error("Cannot find module '"+o+"'");throw 
f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o]
[0].call(l.exports,function(e){var n=t[o][1][e];return s(n?
n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof 
require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})
({1:[function(require,module,exports){

//exact code from Node.js file here


},{"./Factory.js":1}],3:[function(require,module,exports){
var Enumerable, Prototype, Class, Template;

/*
* Code of Prototype Module here
*/

使用的Browserify命令:

browserify index.js > sdk.js

我需要使用在Html页面中生成的这个js代码文件,以便我可以在Javascript中使用对象Factory。

在html中包含js文件之后,我试图通过控制“Factory”来访问它,但它返回undefined。 任何帮助表示赞赏

0 个答案:

没有答案