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

Alex Orekhov avatar  avatar Justice Lu avatar Zack Sargent avatar ThatXliner avatar hiraginoyuki avatar John Murowaniecki avatar Han You avatar Maples7 avatar aaa avatar Tomasz Jakut avatar Eduardo V. avatar Domon avatar Tianqi Han avatar Chenghao Yao avatar Ivan avatar Dreaman Tu avatar Patrick Lienau avatar Ramon Bezerra avatar  avatar Kevin (Kun) "Kassimo" Qian avatar WangYuDong avatar  avatar Joe Esposito avatar Quill avatar bianhao avatar Angus H. avatar Han avatar Zhi Huang avatar  avatar matrixbirds avatar Jiri Spac avatar Austin avatar Gary Gozlan avatar  avatar Michael Anthony avatar Daniel Busłowicz avatar Bharani avatar Pavel Ivanov avatar Tao Huang avatar Andrejs M avatar Armand Zerilli avatar JT avatar Piyush Chauhan avatar Jon Goldsmith avatar Ionel Cristian Mărieș avatar Manu MA avatar p(^-^q) avatar Zhongliang Wang avatar yunsong avatar TUPUNCO avatar Khanh Ngo avatar  avatar weiwenqing avatar Bence Varga avatar Orlando Del Aguila avatar Maxim Malov avatar Tom avatar liwei avatar Justin Obney avatar Sergey Kamardin avatar Eugene Sharygin avatar  avatar Twwy avatar Luke avatar Yorkie Makoto avatar ZhengHaibo avatar Emily Marigold Klassen avatar Hiroshi IKEGAMI avatar Nate Higgins avatar Lincoln Clarete avatar Michael J. Zoidl avatar Matt Juhl avatar Michał Lipek avatar Jarrod Folino avatar Max D avatar Oli avatar  avatar Larry Davis avatar kaixiang avatar taylorchu avatar Akash Devaraju avatar David Chen avatar Christopher Rogers avatar Artur Ostrega avatar Josh Yu avatar  avatar  avatar Ariel Patschiki avatar Minori Yamashita avatar  avatar  avatar Tajima Jumpei avatar Wouter Scherphof avatar Héctor Cerón Figueroa avatar nanha park avatar sharper-than-blade avatar Sascha avatar Christoph Grabo avatar Indamix avatar

Watchers

Tobias Schneider avatar  avatar Michael Anthony avatar Eduardo V. avatar hiraginoyuki avatar

def.js's Issues

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!

nodejs ready?

any chance that this gets compatible with nodejs?

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.