如何使用require()和导出从函数实例化的对象,以及原型方法

How to use require() and export an object instantiated from a function, along with prototype methods?

本文关键字:对象 实例化 方法 原型 函数 require 何使用      更新时间:2023-09-26

这是我试图得到工作的代码:

var SomeObj = function() {
    this.name = 'john';
};

SomeObj.protoype = {
    initialize: function() { }
};
module.exports = SomeObj;

但是我从函数和name属性中获得对象实例化,但没有初始化或其他方法附加到原型中,就像你通常会得到的那样。

我是这样定义我的用于导出RequireJS的

define(
        "SomeObj",
        function(require, exports, modules) {
            var SomeObj= function() {
                //declare attributes and methods to be executed here
            };

            SomeObj.prototype.initialize = function() {
                //all your other method references
            };
            SomeObj.prototype.constructor = SomeObj;
            return SomeObj;
});