Coder Social home page Coder Social logo

poof.js's Introduction

POOF.js Build Status

###Professional Object Oriented Framework for web JavaScript and Node.js### POOF.js is a step towards higher quality, faster, cleaner and more maintainable JavaScript object-oriented code.

===

About

POOF.js is not a new language. It does not require compilation. It is a JavaScript framework providing advanced, powerful and highly efficient features known from other object-oriented languages like Java or C#, such as classes, interfaces, inheritance, accessibility specifiers, constants, static fields and many more. It enforces a clean syntax to help keeping the code maintainable even when large team works on it and provides runtime error checking for those who don't obey.

Release info

POOF.js is currently in Alpha stage. It has gone through numerous iterations and all its functionality is implemented. It is not recommended to be used on projects with strict deadline yet until it goes Beta, but it is surely high time for all developers to start getting familiar with it.

Links

Official website: www.poofjs.org
Download (dev): poof-dev.min.js
Download (prod): poof.min.js

Contact

Maciej Zasada <[email protected]>

===

Table of contents

Documentation

class$

class$(name, options, definition);

name: string, required
Specifies class name. Should begin with capital letter. Should only contain letters and digits.


options: object, required
Class options. Class type, base class, interfaces.
Structure:

{
    type$: int,
    extends$: class,
    implements$: Array
}

type$
Class type. Use one of:

  • class$.PUBLIC: default, public class
  • class$.SINGLETON: Singleton class
  • class$.ABSTRACT: abstract class
  • class$.FINAL: final class. Can only be used in conjunction with one of the primary types above. E.g. class$.PUBLIC | class$.FINAL

extends$
Reference to base class.

implements$
Array of references to interfaces.


definition: object, required
Actual class implementation. See examples for more details.
Structure:

{
    static$: {
        public$: {
            override$: {
            }
        },
        protected$: {
            override$: {
            }
        },
        private$: {
            override$: {
            }
        }
    },
    instance$: {
        public$: {
            override$: {
            }
        },
        protected$: {
            override$: {
            }
        },
        private$: {
            override$: {
            }
        }
    }
}

static$
Static scope. All methods and properties defined within the static$ scope will be assigned to the class object.

instance$
Instance scope. All methods and properties defined within the instance$ scope will be assigned to the instance object.

public$
Public scope. All methods and properties defined within the public$ scope will be accessible from inside and outside of the class's scope as well as its inheritance chain.

protected$
Protected scope. All methods and properties defined within the protected$ scope will be accessible from inside and of the class's scope as well as its inheritance chain. They will not be accessible from outside though.

private$
Private scope. All methods and properties defined within the private$ scope will be accessible only from inside of the class's scope.


interface$

interface$(name, definition);

name: string, required
Specifies interface name. Should begin with capital 'I'. Should only contain letters and digits.


definition: object, required
Actual interface definition. See examples for more details.
Structure:

{
    methodOne: function () {
    },
    methodTwo: function (arg1, arg2) {
    }
}

import$

Import dependency classes and interfaces.
WIP. We recommend using RequireJS for now.

p.js optimizer

Concatenates, minifies and optimises imported files into one.
Soon available!

Examples

Defining classes

Create new instances of defined class.

var ClassName = class$('ClassName', {type$: class$.PUBLIC}, {
});

var instance = new ClassName();

Using constructors

A public instance method named by the class will become the class's constructor.

var ClassName = class$('ClassName', {type$: class$.PUBLIC}, {
    instance$: {
        public$: {
            ClassName: function () {
                // constructor
            }
        }
    }
});

Defining instance fields

Instance fields are being defined within the instance$ scope.

var ClassName = class$('ClassName', {type$: class$.PUBLIC}, {
    instance$: {
        public$: {
            iBelongToInstance: function () {
            }
        }
    }
});

var instance = new ClassName();
instance.iBelongToInstance();

Defining static fields

Static fields are being defined within the static$ scope.

var ClassName = class$('ClassName', {type$: class$.PUBLIC}, {
    static$: {
        public$: {
            iBelongToTheClass: function () {
            }
        }
    }
});

ClassName.iBelongToTheClass();

Using accessibility specifiers

Have full control over your methods and properties thanks to accessibility specifiers.

var ClassName = class$('ClassName', {type$: class$.PUBLIC}, {
    static$: {
        public$: {
            iAmAPublicField: 'public',
            iAmPublic: function () {
                // public
            }
        },
        protected$: {
            iAmAProtectedField: 'protected',
            iAmProtected: function () {
                // protected
            }
        },
        private$: {
            iAmAPrivateField: 'private',
            iAmPrivate: function () {
                // private
            }
        }
    },
    instance$: {
        public$: {
            iAmAPublicField: 'public',
            iAmPublic: function () {
                // public
            }
        },
        protected$: {
            iAmAProtectedField: 'protected',
            iAmProtected: function () {
                // protected
            }
        },
        private$: {
            iAmAPrivateField: 'private',
            iAmPrivate: function () {
                // private
            }
        }
    }
});

Defining constants

Any variable named with only upper-case-with-underscores name will be considered constant.

var ClassName = class$('ClassName', {type$: class$.PUBLIC}, {
    instance$: {
        public$: {
            I_AM_CONSTANT: 'can not change me'
        }
    }
});

Extending classes

Extend from other classes.

var BaseClass = class$('BaseClass', {type$: class$.PUBLIC}, {
    instance$: {
        public$: {
            iBelongToBaseClass: function () {
            }
        }
    }
});

var SubClass = class$('SubClass', {type$: class$.PUBLIC, extends$: BaseClass}, {
});

var instance = new SubClass();
instance.iBelongToBaseClass();

Overriding methods

Methods have to be overridden explicitly. Attempts to override a method implicitly will result in an error. Implementations from the base class can be accessed via public$ reference on the method itself.

var BaseClass = class$('BaseClass', {type$: class$.PUBLIC}, {
    instance$: {
        public$: {
            iBelongToBaseClass: function () {
            }
        }
    }
});

var SubClass = class$('SubClass', {type$: class$.PUBLIC, extends$: BaseClass}, {
    instance$: {
        public$: {
            override$: {
                iBelongToBaseClass: function () {
                    // explicit override
                    this.iBelongToBaseClass.super$();   // call super
                }
            }
        }
});

var instance = new SubClass();
instance.iBelongToBaseClass();

Defining Final classes

Final classes cannot be extended.

var ClassName = class$('ClassName', {type$: class$.PUBLIC | class$.FINAL}, {
});

Defining Abstract classes

Abstract classes can only be extended, but cannot be instantiated directly.

var ClassName = class$('ClassName', {type$: class$.ABSTRACT}, {
});

Defining Singleton classes

Singleton classes have only one instance across your entire application. They cannot be instantiated directly. Instead, instance field is used to reference the class's instance.

var ClassName = class$('ClassName', {type$: class$.SINGLETON}, {
});

var instance = ClassName.instance;

Defining interfaces

You can define interfaces in the following way.

var IInterface = interface$('IInterface', {
    methodOne: function (arg1, arg2) {
    },
    methodTwo: function () {
    }
});

Implementing interfaces.

Use interfaces to enable class definition validation against missing methods.

var IInterface = interface$('IInterface', {
    methodOne: function (arg1, arg2) {
    },
    methodTwo: function () {
    }
});

var ClassName = class$('ClassName', {type$: class$.PUBLIC, implements$: [IInterface]}, {
    instance$: {
        public$: {
            methodOne: function (arg1, arg2) {
            },
            methodTwo: function (arg2, arg2) {
            }
        }
    }
});

Using RequireJS

You can use POOF.js with RequireJS very easily.

define([], function () {
    var BaseClass = class$('BaseClass', {type$: class$.PUBLIC}, {
    });
    
    return BaseClass;
});

define(['BaseClass'], function (BaseClass) {
    var SubClass = class$('SubClass', {type$: class$.PUBLIC, extends$: BaseClass}, {
    });
    
    return SubClass;
});

poof.js's People

Contributors

maciejzasada avatar

Watchers

Doru Cioclea avatar James Cloos 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.