Recommend this page to a friend! |
Download .zip |
Info | View files (3) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2012-10-28 (4 years ago) | Not enough user ratings | Total: 138 | All time: 322 This week: 16 |
Version | License | JavaScript version | Categories | |||
extend 1.0 | Free For Educatio... | 1.8 | Language |
Description | Author | |||||||||||||
This object can be used to create new objects that extend other objects. |
|
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` |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
0% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.