Have ideas to improve npm?Join in the discussion! »


1.0.1 • Public • Published

Hello my name is Bradley Matusiak and this is my function class cextend 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 cextend.js script require("./cextend.js"); for browsers you need to load it in manualy

So now that being said, lets make a example.

function _SuperClass() {

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.cextend(_SuperClass);
var SubClass = SuperClass.cextend(_SubClass);

so basically what cextend 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


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.cextend(Array,MyArray);
var myarray = new 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.cextend(Array,MyArray);
var myarray = new MyArray();

Console Output: adding test1 to my array

doing this can help with debugging/testing and special tasks in any object




npm i cextend

DownloadsWeekly Downloads






Last publish


  • avatar