In html5 come posiziono la classe di seguito (costruttore e metodo) in un altro file e la riferimento nel file html.posto javascript in html5 nel file esterno
Sotto ho tutto in 1 file e non lo voglio.
<canvas id="myCanvas" width="600" height="400"></canvas>
<script>
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
ctx.font="14px Arial";
//how to move to other file
function ClassPerson(gender,name1) {
var aa;
this.gender=gender;
this.name1=name1;
aa=6;
};
//how to move to other file
ClassPerson.prototype.m_sayGender = function()
{
ctx.fillText("this gender= " + this.gender + " gender=" + this.name1,10,40);
};
//stay in this file
var person1 = new ClassPerson('male','dave');
var person2 = new ClassPerson('female','bet');
ctx.fillText("this gender= " + person1.gender,10,20);
person1.m_sayGender();
myObject._three();
</script>
ok che funziona, ma perché ho ottenuto un voto di -1? Il mio esempio era senza un'immagine che è quello che volevo chiedere. Come posso accedere a un'immagine caricata in una classe da un altro file usando canvas/html5. – jagguy
Non posso fare un'altra domanda e incollare il codice di ciò di cui sto parlando? Non riesco ad accedere all'immagine da una classe. – jagguy
Verifica questo: http://stackoverflow.com/questions/8050573/how-can-i-use-a-variable-from-an-external-js-file-in-my-html – Jacob