By Piotr Sikora

  • javascript

Have you been creating your own classes in pure JavaScript?

What if you neeed a private method? How to create them?

var MyClass = (function() {
        function MyClass() {
        }

        var prvMethod = function() {
               console.log('method');
        };

        MyClass.prototype = {
            init: function() {
                console.log('init ');
                prvMethod();

            }

        };

        return MyClass;
    })();

var mc = new MyClass();
mc.init();

So finally you can access init() but cannot access prvMethod(). It has only access into MyClass() function scope.

Categories

Recent Posts

About Me

Piotr Sikora - Process Automation | AI | n8n | Python | JavaScript

Piotr Sikora

Process Automation Specialist

I implement automation that saves time and money, streamlines operations, and increases the predictability of results. Specializing in process automation, AI implementation, and workflow optimization using n8n, Python, and JavaScript.

n8n Workflows

n8n workflow automation templates

Explore my workflow templates on n8n. Ready-to-use automations for blog management, data collection, and AI-powered content processing.

3Workflow Templates

• Auto-Categorize Blog Posts with AI

• Collect LinkedIn Profiles

• Export WordPress Posts for SEO

Similar Articles

Discover more related content

Unleash the Power of Autoexecuted Objects in JavaScript

Sometimes you will need to create autoexecuted object (for example in case of load/document ready events)

Raspberry Pi node.js and how to start with programming GPIO

Start programming Raspberry Pi GPIO with Node.js. Introduction to the PixPress project on GitHub. Hardware meets JavaScript.

Image to HTML table. Transform image to HTML table.

Image to HTML table. Transform image to HTML table.

I heard very interesting story about improvements in delivery of emailers.