How do prototypes in js add functions?

currently encapsulated table plug-ins are as follows:

(function ($) {

    function Table() {

        this.config = {
           //
        }

    };

    Table.prototype = {
       //table
        rend: function (config) {

            return this;
        }
    };

    window.Table = Table;

}(jQuery));

plugin call method:

var abc = new Table();
abc.rend({
    ele:"-sharptable1"
});

question: there are some functions that belong to rend customization that I want to write into HyTable.prototype "s rend, but will this result in a closure? Will it cause a memory leak if there are too many functions defined? Or is there a better way?

Mar.23,2021

1. Closures will not be generated. Specifically, you can see the definition of closures
2. Memory leaks are related to whether the data has been released. If you just use it up and do not reference it elsewhere, it will not cause memory leaks
3. If you want to define a lot of functions, put them in rend, which will affect the readability of the code. You can define functions on Table.prototype


.

there is no problem at all, and it is often necessary to define methods within a method that can only be used within that method, even if only for the readability of the code.

Table.prototype = {
    render:function(config){
        function a(){}
        
        function b(){}
        
        ......
    }

}

Table.prototype.addFunc = function(){}

write complete OK in this way

Menu