Q:

JavaScript object inheritance issues

Hi please be patient with me. I am a PHP developer entering the world of javaScript. Now I'm building a grid that will contain blocks of different size. I want a base block with all the methods on it and then other blocks that extend this (to use its methods) but with different properties. I have done a lot of reading but dont seem to be able to find a consistent method. I have put together some code i though would work but it doesn't. SmallBlock in the example has its own properties but none of Blocks properties
    // Simple extend function to add for creating object inheritance
    function extend(Child, Parent) {
        var Temp = function(){
            Temp.prototype = Parent.prototype;
            Child.prototype = new Temp();
            Child.prototype.constructor = new Child();
        }
    }

    //__________________________________________________
    // ## OBJECT DECLARATIONS  ##
    //__________________________________________________

    //__________________________________________________
    // ## BLOCK ##
    // Base object representing a block/tile in the grid
    var Block = function(){

        // The X position block
        this.positionX = 0;

        // The Y position block
        this.positionY = 0;

        // The height of the block
        this.height = 0;

        // The width of the block
        this.width = 0;

        // The horizontal orientation of a block
        this.blockHorizontalOrientation = null;

        // The vertical orientation of a block
        this.blockVerticalOrientation = null;

        // Method to set the width of a block
        this.setWidth = function(width){
            this.width = width;
        };

        // Method to set the height of a block
        this.setHeight = function(height){
            this.height = height;
        };

        // Method to get the width of a block
        this.getWidth = function(){
            return this.width;
        };

        // Method to get the height of a block
        this.getHeight = function(){
            return this.height;
        };

        // Method to set the X position of a block (in the grid)
        this.setPosX =  function(posX){
            this.positionX = posX;
        };

        // Method to set the Y position of the block (in the grid)
        this.setPosY = function(posY){
            this.positionY = posY;
        };

        // Method to get the Y position of the clock
        this.getPosY = function(){
            return this.positionY;
        };

        // Method to get the X position of the clock
        this.getPosX = function(){
            return this.positionX;
        };

        // Method to get the horizontal orientation
        this.getHOrientation = function(){
            return this.blockHorizontalOrientation;
        };

        // Method to get the vertical orientation
        this.getVOrientation = function(){
            return this.blockVerticalOrientation;
        };

        // Method to get the horizontal orientation
        this.setHOrientation = function(hOren){
            this.blockHorizontalOrientation = hOren;
        };

        // Method to get the vertical orientation
        this.setVOrientation = function(vOren){
            this.blockVerticalOrientation = vOren;
        };
    }

    //__________________________________________________
    // ## SMALL BLOCK ##
    // object representing a small block/tile in the grid -- extends Block
    var BlockSmall = function(){

        // The X position block
        this.positionX = 0;

        // The Y position block
        this.positionY = 0;

        // The height of the block
        this.height = 1;

        // The width of the block
        this.width = 1;

        // The horizontal orientation of a block
        this.blockHorizontalOrientation = null;

        // The vertical orientation of a block
        this.blockVerticalOrientation = null;
    };

    // EXTENDING BLOCK
    extend(BlockSmall, Block);

Please can somebody review this code and help by advising what it is i am doing wrong. Again please be patient with me if I am miles out. This is all brand new concepts to me.

A:

Well, this should work for inheriting:
function extend(Child, Parent) {
  Child.prototype = new Parent();
  Child.constructor = Child;
}

In your code, you just define a function inside extend that never gets called.

