Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
class with static and instance methods

The goal - create function, that behaves like class with static methods and at the same time can be used to create instanses. All this resides in dedicated namespace. I am looking for "standard" ptototype approach. And is it good practice in general? I tried to avoid use reference to "class" by function name. If I would have 10 or more static methods it could be difficult. In first example I used _self, and in another method defineProperties.

var MyNamespace = (function() {
    
    function MyClass0(e) {
        this.e = e;
        var _self = MyClass0;
        
        _self.prototype = {
            instanceMethod: function() {
                
            }
        }
        _self.staticMethod = function() {
            
        }
        if (!e) {
            return _self;
        }
    }
    function MyClass1(e) {
        this.e = e;
        MyClass1.prototype = {
            instanceMethod: function() {
                
            }
        }
        var properties = {
                staticMethod: {
                    value: function() {
                }
            }
        };
        Object.defineProperties(MyClass1, properties)
        if (!e) {
            return MyClass1;
        }
    }

    return {
        MyClass0: MyClass0(), // use _self
        MyClass1: MyClass1() // use defineProperties
    }
})();
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!