Skip to main content
added 97 characters in body
Source Link
David G
  • 97.9k
  • 41
  • 174
  • 258

I am new to OO in JavaScript and trying to make this simple canvas demo:

var c; // typeof c is the canvas element
function SolarSystem(plane, sun) {

    this.plane = plane; // typeof plane is object,Canvas aCtxt
 Canvas 2D Context
 this.sun = sun;

    this.init = function () {
        draw();
    }


    this.render = function () {
        c.height = c.height;
        requestAnimationFrame(this.render);
        this.draw();
    }

    this.draw = function () {
        console.log(1);
    }

}

}

What I want to do is, to render SolarSystem, I want to call render() that is inside of it. I cannot call render() from render(), how can I do that without getting Uncaught TypeError: Type error in the console? Thanks!

I am new to OO in JavaScript and trying to make this simple canvas demo:

var c; // typeof c is the canvas element
function SolarSystem(plane, sun){

this.plane = plane; // typeof plane is object, a Canvas 2D Context
this.sun = sun;

this.init = function(){
    draw();
}


this.render = function(){
    c.height = c.height;
    requestAnimationFrame(this.render);
    this.draw();
}

this.draw = function(){
    console.log(1);
}

}

What I want to do is, to render SolarSystem, I want to call render() that is inside of it. I cannot call render() from render(), how can I do that without getting Uncaught TypeError: Type error in the console? Thanks!

I am new to OO in JavaScript and trying to make this simple canvas demo:

var c; // typeof c is the canvas element
function SolarSystem(plane, sun) {

    this.plane = plane; // typeof plane is Canvas Ctxt
    this.sun = sun;

    this.init = function () {
        draw();
    }


    this.render = function () {
        c.height = c.height;
        requestAnimationFrame(this.render);
        this.draw();
    }

    this.draw = function () {
        console.log(1);
    }

}

What I want to do is, to render SolarSystem, I want to call render() that is inside of it. I cannot call render() from render(), how can I do that without getting Uncaught TypeError: Type error in the console? Thanks!

Source Link
hyde
  • 2.6k
  • 4
  • 27
  • 52

Call JS Function inside an Object

I am new to OO in JavaScript and trying to make this simple canvas demo:

var c; // typeof c is the canvas element
function SolarSystem(plane, sun){

this.plane = plane; // typeof plane is object, a Canvas 2D Context
this.sun = sun;

this.init = function(){
    draw();
}


this.render = function(){
    c.height = c.height;
    requestAnimationFrame(this.render);
    this.draw();
}

this.draw = function(){
    console.log(1);
}

}

What I want to do is, to render SolarSystem, I want to call render() that is inside of it. I cannot call render() from render(), how can I do that without getting Uncaught TypeError: Type error in the console? Thanks!