Javascript 在原型外部访问画布
我想在每次点击按钮时更改HTML画布上基于代码的图像的颜色。画布/对象的代码不是我的代码。问题是我无法更改甚至无法访问c.B.原型和颜色之外的访问();部分 简言之:Javascript 在原型外部访问画布,javascript,canvas,meteor,Javascript,Canvas,Meteor,我想在每次点击按钮时更改HTML画布上基于代码的图像的颜色。画布/对象的代码不是我的代码。问题是我无法更改甚至无法访问c.B.原型和颜色之外的访问();部分 简言之: 如何访问另一个文件中的画布和图像的颜色(因此超出了原型和颜色函数的范围) 这是按钮的JS代码,我想在这里访问画布和颜色(代码基于Meteor) 这是图像代码的一部分(在另一个文件中)。HTML元素有一个画布渲染器,因此getAttribute就是用于此目的的h'稍后被分配给performance.now()等函数;比如说 (f
- 如何访问另一个文件中的画布和图像的颜色(因此超出了原型和颜色函数的范围)
(function(z, h) {
function colors(x) {
this.element = x; //this refers to the image in the HTML
this.B = x.getAttribute("colour") || "red"; //this refers to the current colour rendered in the HTML
this.b = {
background: "white",
};
switch (this.B) {
case "pink":
this.b.background = "pink";
break;
}
this.createCanvas()
c.W.prototype = {
createCanvas: function() {
this.element = h.createElement("canvas");
this.element.className = "fill";
this.ctx = this.element.getContext("2d");
this.x.element.appendChild(this.element);
},
c.canvas =
c.W;
c.n = function(x) {
this.x = x
}; //after this follows: a c.n prototype{}
})(window, document);
非常感谢您的帮助:)很遗憾,您遗漏了实际回答此问题所需的大部分代码。例如,谁调用
colors()
?在哪里定义了h
?对于colors()
,此的数据上下文是什么?谢谢,我更新了代码。有很多代码(超过500行),有很多这样的赋值。a=this.c。有点难弄清楚需要发布什么。现在理解更好吗?
(function(z, h) {
function colors(x) {
this.element = x; //this refers to the image in the HTML
this.B = x.getAttribute("colour") || "red"; //this refers to the current colour rendered in the HTML
this.b = {
background: "white",
};
switch (this.B) {
case "pink":
this.b.background = "pink";
break;
}
this.createCanvas()
c.W.prototype = {
createCanvas: function() {
this.element = h.createElement("canvas");
this.element.className = "fill";
this.ctx = this.element.getContext("2d");
this.x.element.appendChild(this.element);
},
c.canvas =
c.W;
c.n = function(x) {
this.x = x
}; //after this follows: a c.n prototype{}
})(window, document);