some samples on js
This commit is contained in:
140
js1.html
Normal file
140
js1.html
Normal 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>
|
||||
Reference in New Issue
Block a user