Extend: Create new objects that extend other objects

Recommend this page to a friend!
     
  Info   View files Files   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 142 All time: 346 This week: 4Up
Version License JavaScript version Categories
extend 1.0Free For Educatio...1.8Language
Description 

Author

This object can be used to create new objects that extend other objects.

It defines the extend prototype function that can create a new object extending another of a given parent class.

The new object can be defined with a given subclass definition.

Picture of Bradley Matusiak
Name: Bradley Matusiak <contact>
Classes: 1 package by
Country: United States United States
Age: 37
All time rank: 14617 in United States United States
Week rank: 6 Up2 in United States United States Up

Details

Hello my name is Bradley Matusiak and this is my function class extend function, not saying it never been done before :P. I also think you should also try to build you own :P My main goal is to create a class base way of thinking to hold a un initialized copy of itself via `OBJECT._this` and also have location to it parent via `OBJECT._this._parent` *all my examples should allready have loaded my extend.js script `require("./extend.js");` for browsers you need to load it in manualy So now that being said, lets make a example. function _SuperClass() { console.log(this._this.name)//_SubClass } function _SubClass() { if (this.base) this.base(); } ok so i created a file called test.js and i made two functions. and i added. var SuperClass = _SuperClass.extend(_SuperClass); var SubClass = SuperClass.extend(_SubClass); so basically what extend did was manage the `prototype` objects that where overwrite to allow .base() function. this function also return what the parent function was to return, arguments to base function are passed to parent also. so lets init the class var sc = new SubClass(); the output should be in console output _SubClass why isent this `_SuperClass`, well that is because `new SubClass()` aka `_SubClass` this means its running as a child of _SuperClass. *note doing anonymous functions will not have a _this.name ex `var _SuperClass = function(){}`, class style has to be `function _SuperClass(){}` to have a name! ------ ok that was a simple exampe of how this thing really is. lets take over a Array object to really get down and dirty function MyArray() { return this.base(); } var MyArray = MyArray.extend(Array,MyArray); var myarray = new MyArray(); myarray.push("test1"); console.log(myarray); Console Output: `{ '0': 'test1', length: 1 }` ok pretty simple right, so lets add a prototype to it function MyArray() { return this.base(); } MyArray.prototype.push=function push(arg1){ console.log("adding",arg1,"to my array"); return this.base(arg1); }; var MyArray = MyArray.extend(Array,MyArray); var myarray = new MyArray(); myarray.push("test1"); Console Output: `adding test1 to my array`

  Files folder image Files (3)  
File Role Description
Plain text file README.md Doc. README.md
Plain text file extend.js Class function.prototype.extend function
Accessible without login Plain text file test Example test file for extend.js

 Version Control Unique User Downloads Download Rankings  
 0%
Total:142
This week:0
All time:346
This week:4Up