[Vuejs]-Prototype function vue.js

0👍

I don’t see a problem with your first example? The variables can be reached, I log them here in the console.

Maybe you forgot to define ctx globally?

 function Shape(x, y, w, h, fill) {
    this.x = x || 0;
    this.y = y || 0;
    this.w = w || 1;
    this.h = h || 1;
    this.fill = fill || '#AAAAAA';
    
    this.draw()
}

Shape.prototype.draw = function(ctx) {
    console.log("variables of Shape:")
    console.log(this.x)
    console.log(this.fill)
}

let s = new Shape(30,30,30,30,"#EEF")
s.draw()

Leave a comment