Code Monkey home page Code Monkey logo

prodecjs's Introduction

Basic usage

Prodecjs adds ability to add protected scope to your classes.

var A = Declare({
	public     : function() {
		// calling protected function
		_protected();
	},
	_protected : function() {
		alert( 'Protected called' );
	}
});

Prodecjs can be used as the constructor replacer for creating protected scope in JavaScript.

var A = Declare();
A.prototype._protected = function() {
	alert (' Protected called');
}

A.prototype.public = function() {
	_protected();
}

Inheritance

Inherited functions can be called by using $super object and the function name. All inherited functions are making deal out of the protected scope. As example :

var A = Declare({
	public     : function() {},
	_protected : function() {}
});

var B = Declare(A, {
	test : function() {
		// calling public inherited function
		$super.public();

		// calling protected inherited function
		$super._protected();
	}
});

Limitations :

Prodecjs has number of limitations. You should be aware of them before will start asking question "Why this is not working?"

  • First of all inheritance is not possible via old school style. Meaning that inheritance always should be done with help of Decalre.

    Bad way :

      function A(){}
    
      function B(){}
      B.prototype = new A();
    

    Good way :

      var B = Declare(A,{});
    
  • Second limitation concerns the runtime instances when new prototype member is added. If you add member to the prototype of the class it will be unavailable in all created instances. This limitation also can be seen as a good point, no one will be able to hijack the instantiated objects.

  • Third limitation does not allow to access scope which was available at the moment of the prototype member creation. Take a look at example :

    var watch() { alert('B.bork is called'); }

    B.prototype.bork = function() { watch(); }

Such situation is not possible, despite the fact that the scope with watch function were available at the moment of creation.

prodecjs's People

Stargazers

Maks Nemisj avatar

Watchers

Maks Nemisj avatar James Cloos avatar  avatar

Forkers

tgorge

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.