Giter Site home page Giter Site logo

class.def's Introduction

Class.def

This is an extendtion to Class that allows extending Classes in a ruby like syntax. This implementation was inspired by the very cool Def.js lib.

How to use

Simple Use

To create a new Class from scratch, we can use both the default Class construction method, or like this:

#JS
new Class.def("Preson") << new Class({
    initialize : function(name){
        this.name = name;
        console.log('My Name Is '+name+' And I Am '+this.power+' strong!');
    }
   ,power : 1
});

To extend a Class (this can be done with any Class):

#JS
new Class.def('Ninja') << new Person({
    power :20
});

new Person('Bob'); //My Name is Bob And I Am 1 strong!
new Ninja('Lee'); //My Name Is Lee and i am 20 strong!

NOTE: It is very important that you use the new operator on both, or the execution order will get break

This should work on any instance of Class, no matter how it was defiened.

Limitations:

  1. You must make sure you use the new operator for both the Class.def and the inherited Class.
  2. Make sure you never call Class.def without using the full syntax (<< new Class). Doing so might make the following Class instantiation fail.
  3. I have obviosly not tested this too much, so use with caution.

Notes On version 1.1

  1. You can now only create Classes using the << operator (well, actually, any numeric operator will do).
  2. You can no longer create Classes via passing a second argument. This is to make sure the syntax is used correctly.

class.def's People

Stargazers

 avatar

Watchers

 avatar  avatar

class.def's Issues

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.