npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

plus.class

v1.0.3

Published

Class and inheritance

Downloads

6

Readme

Class

Should allow to create Classes

should create simple hello Class 

require `src/Class.js` as `Class`            
code:                                        
  """
  ```
      var MyClass = Class({

          name: 'name1',

          hello: function () {
              return 'hello ' + this.name;
          }

      });

      var instance = new MyClass();
  ```
  """
`instance.name` should equal 'name1'          
`instance.hello()` should equal 'hello name1' 

should allow to construct with methods: init, _new, _constructor, _construct 

require `src/Class.js` as `Class`                                                
code:                                                                            
  """
  ```
      var MyClass = Class({
          init: function () {
              this.name = 'xxx'
          }
      });

      var instance = new MyClass();
  ```
  """
`instance.name` should equal 'xxx'                                                

should allow to use factory class 

require `src/Class.js` as `Class`     
code:                                 
  """
  ```
       var object = {xx: 'an object'};

      var MyClass = Class({
          init: function () {
              return  object;
          }
      });

      var instance = new MyClass();
  ```
  """
`instance` should equal `object`       

should allow to extends 

require `src/Class.js` as `Class`                
code:                                            
  """
  ```
      var MyClass1 = Class({

          name1: 'name1',
          name2: 'name2',

          hello1: function () {
              return 'hello ' + this.name1;
          },

          hello2: function () {
              return 'hello ' + this.name2;
          }

      });

      var MyClass2 = Class(MyClass1, {

          name1: 'name1-1',

          hello2: function () {
              return 'hello2 ' + this.name2;
          }
      });

  ```
  """
code `var instance = new MyClass1();`             
`instance.hello1()` should equal 'hello name1'    
`instance.hello2()` should equal 'hello name2'     
`instance` should be instanceOf `MyClass1`         
code `var instance2 = new MyClass2();`            
`instance2.hello1()` should equal 'hello name1-1' 
`instance2.hello2()` should equal 'hello2 name2'   
`instance2` should be instanceOf `MyClass1`        
`instance2` should be instanceOf `MyClass2`        

should allow to call _super 

require `src/Class.js` as `Class`                          
code:                                                      
  """
  ```
      var MyClass1 = Class({

          name: 'name1',

          hello: function () {
              return 'hello ' + this.name;
          }
      });

      var MyClass2 = Class(MyClass1, {
          hello: function () {
              return this._super() + '-class2';
          }
      });

      var MyClass3 = Class(MyClass2, {
          hello: function () {
              return this._super() + '-class3';
          }
      });

  ```
  """
code `var instance = new MyClass2();`                       
`instance.hello()` should equal 'hello name1-class2'        
code `var instance = new MyClass3();`                       
`instance.hello()` should equal 'hello name1-class2-class3' 

should allow to call _super in the constructor 

require `src/Class.js` as `Class`                  
code:                                              
  """
  ```
      var MyClass1 = Class({
          init: function (name3) {
              this.name1 = 'name1';
              this.name2 = 'name2';
              this.name3 = name3;
          }
      });

      var MyClass2 = Class(MyClass1, {
          init: function () {
              this._super('name3-updated');
          }
      });

  ```
  """
code `var instance = new MyClass1('name3');`        
`instance.name1` should equal 'name1'               
`instance.name2` should equal 'name2'                
`instance.name3` should equal 'name3'                
code `var instance = new MyClass2();`               
`instance.name1` should equal 'name1'               
`instance.name2` should equal 'name2'                
`instance.name3` should equal 'name3-updated'        

should copy static methods vars 

require `src/Class.js` as `Class`                                 
code:                                                             
  """
  ```
      var MyClass1 = Class();

      MyClass1.staticMethod1 = function () {

      }

      MyClass1.staticVar1 = 100;

      var MyClass2 = Class(MyClass1);
  ```
  """
`MyClass2.staticMethod1 === MyClass1.staticMethod1` should be true 
`MyClass2.staticVar1 === MyClass1.staticVar1` should be true       

should allow to create sub classes simply 

require `src/Class.js` as `Class`               
code:                                           
  """
  ```
      var MyClass1 = Class();
      var MyClass2 = Class(MyClass1);
  ```
  """
`new MyClass1()` should be instanceOf `MyClass1` 
`new MyClass2()` should be instanceOf `MyClass1` 
`new MyClass2()` should be instanceOf `MyClass2` 

should construct with parent constructor 

require `src/Class.js` as `Class`            
code:                                        
  """
  ```
      var MyClass1 = Class(function () {
          this.name = 'xxx';
      });

      var MyClass2 = Class(MyClass1);
  ```
  """
code `var instance = new MyClass2();`         
`instance.name` should equal 'xxx'            

should create class with "new" 

require `src/Class.js` as `Class`   
code:                               
  """
  ```
      var MyClass = new Class({
          init: function () {
              this.hi = 'hello'
          }
      });
  ```
  """
code `var instance = new MyClass();` 
`instance.hi` should equal 'hello'   

10 scenarios (10 passed) 54 steps (54 passed)