Vediamo qual è lo scope per una variabile dichiarata dentro e fuori da una funzione...
<html> <head> <script> var cerchio=function(){ variabile =123; } cerchio(); alert (variabile); </script> </head> <body bgcolor = cyan> </body> </html>così facendo ottengo
123
Se dichiaro la variabile con this che succede?
<html> <head> <script> var cerchio=function(){ this.variabile =123; } cerchio(); alert (variabile); </script> </head> <body bgcolor = cyan> </body> </html>ottengo
123quindi è esattamente la stessa cosa...
Nessun commento:
Posta un commento