some samples on js

This commit is contained in:
2014-11-23 22:06:08 +01:00
parent be34f479d5
commit 2b9b60c413
9 changed files with 422 additions and 0 deletions

140
js1.html Normal file
View File

@@ -0,0 +1,140 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
try {
var a = 1;
document.writeln(window.a);
document.writeln("<br>");
function persona(nome, cognome) {
this.nome = nome;
this.cognome = cognome;
this.join= function(){return this.nome + this.cognome};
}
mario = new persona("mario","marra");
mario.eta = 5;
document.writeln(mario.eta);
gino = new persona("gino","foff");
persona.prototype.eta=0;
document.writeln(gino.eta);
document.writeln(gino.join());
document.writeln("<br>");
for (i=0;i<5;i++){
document.writeln("<p>\"Io sono il num\" " + i);
}
document.writeln(i);
document.writeln("<br>");
/* bad bad
c="c";
c.a="aa";
document.writeln(c.a);
*/
c= new String("c");
c.a="aa";
document.writeln(c.a);
document.writeln("<br>");
document.writeln("3" + 4);
document.writeln(3 + "4");
document.writeln(parseInt("3") + 4);
document.writeln("3".valueOf() + 4);
document.writeln(String(3) + 4);
document.writeln("<br>");
document.writeln(mario.toString());
document.writeln(mario.valueOf());
document.writeln("<br>");
global = 1
function g (){
var global = 2; // this hide global
document.writeln(global);
function g1 (){
document.writeln(global);
}
g1();
}
g();
document.writeln(global);
req = prompt("aa");
if (req){
document.writeln(req);
} else{
document.writeln("cancel " + req);
}
}catch (e) {
document.writeln(e.message);
}
</script>
</body>
</html>