Giter Site home page Giter Site logo

def.js's Introduction

Simple Ruby-style inheritance for JavaScript

Example

def ("Person") ({
	init: function(name){
		this.name = name;
	},
	
	speak: function(text){
		alert(text || "Hi, my name is " + this.name);
	}
});

def ("Ninja") << Person ({
	init: function(name){
		this._super();
	},
	
	kick: function(){
		this.speak("I kick u!");
	}
});

var ninjy = new Ninja("JDD");

ninjy.speak();
ninjy.kick();

def.js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

def.js's Issues

nodejs ready?

any chance that this gets compatible with nodejs?

Deferred's valueOf should clean up _props and _super

It seems like not deleting or resetting deferred._super and deferred._props after valueOf() is done could lead to odd behavior, e.g. if someone should happen to hold a reference to the deferred created by def("MyClass") and do something that invokes valueOf() a second (or third, or fourth…) time, unexpected things could happen to the prototype.

While this example is a bit contrived who knows what odd things might occur in real use:

def ("Person") ({
    init: function(name){
        this.name = name;
    },

    speak: function(text){
        alert(text || "Hi, my name is " + this.name);
    }
});

var NinjaDef = def ("Ninja");
NinjaDef << Person ({
    init: function(name){
        this._super();
    },

    kick: function(){
        this.speak("I kick u!");
    }
});

Person ({
    guns: true
});

// This is a bit contrived, but... who knows what odd thing could happen to cause valueOf() to run
NinjaDef + 5;

var ninjy = new Ninja("JDD");
console.log("ninjy.name: ", ninjy.name); // should be JDD
console.log("ninjy.guns: ", ninjy.guns); // Ninjas don't use guns!

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.