Javascript 原型函数错误:不是函数

Javascript 原型函数错误:不是函数,javascript,Javascript,我试图封装一个javascript对象,并声明了一些原型函数。但也有一些错误 这是我的密码: const editor_theme = require('./editor-theme.js') let defaultTheme = new editor_theme.Editor_Theme('{"titlebar_color": "f0f0f0", "background_color": "ffffff"}') defaultTheme.setTitlebarColor('888888') c

我试图封装一个javascript对象,并声明了一些原型函数。但也有一些错误

这是我的密码:

const editor_theme = require('./editor-theme.js')

let defaultTheme = new editor_theme.Editor_Theme('{"titlebar_color": "f0f0f0", "background_color": "ffffff"}')
defaultTheme.setTitlebarColor('888888')
console.log(defaultTheme.getTitlebarColor())

//main.js

module.exports = {
    Editor_Theme: function (data) {
        var _themeData = JSON.parse(data)

        var _titlebar_color = _themeData.titlebar_color
        var _background_color = _themeData.background_color

        const Func = function() { }

        Func.prototype = {
            getTitlebarColor : function () {
                return _titlebar_color
            },
            getBackgroundColor : function () {
                return _background_color
            },
            setTitlebarColor : function (titlebarColor) {
                _titlebar_color = titlebarColor || _titlebar_color
            }
        }

        Object.freeze(Func)
        Object.freeze(Func.prototype)

        return Func
    }

}


//editor-theme.js
错误日志如下所示:

未捕获类型错误:defaultTheme.setTitlebarColor不是函数


您的构造函数现在返回另一个构造函数,而不是对象。而是返回该构造函数的实例:

//module.exports={
设moduleExports={
编辑器主题:函数(数据){
var\u-motedata=JSON.parse(数据)
var\u titlebar\u color=\u主题数据。titlebar\u color
var\u background\u color=\u themeData.background\u color
const Func=函数(){}
函数原型={
getTitlebarColor:function(){
返回标题栏颜色
},
getBackgroundColor:function(){
返回背景色
},
setTitlebarColor:函数(titlebarColor){
_标题栏颜色=标题栏颜色
}
}
对象冻结(Func)
对象冻结(函数原型)
返回new Func()//实例化构造函数
}
}
//const editor_theme=require('./editor theme.js')
常量编辑器\u主题=模块导出
让defaultTheme=neweditor\u theme.editor\u theme('{“标题栏颜色”:“f0f0f0”,“背景颜色”:“ffffff”}'))
defaultTheme.setTitlebarColor('888888')
console.log(defaultTheme.getTitlebarColor())