Giter Site home page Giter Site logo

shortjs's Introduction

ShortJs

Awesome Class features and package manager for javascript.

###This Library provides following features.

  • Creating Javascript Classes.
  • Inheriting(Single, Multiple, Multilevel) Javascript Classes.
  • Importing Javascript Files.
  • Maintaining and packaging javascript files.

Class

####This variable supports following methods.

  • define
  • new
  • extends
  • logStructures

Defining a class

Class.define("ClassName",function(){
        
        var x=10;
        var y=20;
        
        this.sampleMethod = function(){
                
                alert("Hello world");
                alert(x+y);
        }
        });

Creating object of class

var classNameObject = Class.new("ClassName");

//calling method of class
className.sampleMethod();

Defining class constructor

Defined as a normal method but it's name and class name should be same.

Class.define("Calculator",function(){
        
        var x,y;
        
        this.someValue="SuperValue";
        
        //Constructor. Notice the name of this method is "Calculator" which is also the name of the class.
        this["Calculator"]=function(){
                x=10;
                y=20;
        }
        
        this.add = function(x,y){
                
                return x+y;
        }
        });

Inheriting other classes

With the help of this library one can inherit one or more class,i.e Single, Multiple, Multilevel inheritance is now possible with the help of this library.

Now we are going to extend above defined class.

Class.extend("Calculator").define("MyCalculator",function(){
        
        this.someValue="Not a Super value. :)";
        this.subtract=function(x,y){
                        return x-y;
                }
});
        

Use of Super.

In the above defined class both the parent class and sub class have public variable this.someValue.We can access parent variable by using Super variable.

var myCalculatorObj=Class.new("MyCalculator");

alert(myCalculatorObj.someValue);//displays "Not a Super value. :)"
alert(myCalculatorObj.Super.Calculator.someValue);//displays "SuperValue"

//or
alert(myCalculatorObj.Super["Calculator"].someValue);//displays "SuperValue"

Package(WIP)

Could be added at multiple places in a file. Package("com.example.testFolder");

Include

As of right now * is not supported while including js files.

Include("com.example.testFolder.className1");

  • Usefull for conditionally loading js files.
if(someConditionIsTrue)
{
        Include("com.example.testFolder.className1");
}
else
{
        Include("com.example.testFolder.className2");
}

Things that are not recommended.

Putting your code in open.

Class.define("TestClass",function(){
        var x=10;
        alert(x);//not recommended.
});

Recommended Way:-

Class.define("TestClass",function(){
        var x=10;
        
        this.show=function(){
           
           alert(x);                
        }
});

shortjs's People

Contributors

anubhavg-optimus avatar anubhavgupta avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.