1.JS未使用var定义的变量是全局变量:
例子: 说明b成为了全局变量 而 a是局部变量
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <input type="button" value="点击" onclick="al();"> <input type="button" value="点击" onclick="al2();"> </body> <script lang="javascript"> function al(){ var a=b=3; console.log(a); // 3 console.log(b); //3 } function al2(){ //console.log(a); //报错 未定义 console.log(b); //3 } </script> </html>
2.javascript是单线程逻辑。在一个线程完成之前,另一个方法不执行:
例子:
//系统会一直执行start 因为单线程导致setTimeout一直无法进行
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <input type="button" value="点击" onclick="get();"> </body> <script lang="javascript"> function get(){ var t = true; window.setTimeout(function (){ t = false; },1000); while (t){alert('start');} //系统会一直执行start 因为单线程导致setTimeout一直无法进行 alert('end'); } </script> </html>
3.javascript声明前置
例子;
javascript会默认在函数第一行里面进行声明 var a; 所以函数内alret 是undifined
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <input type="button" value="点击" onclick="get();"> </body> <script lang="javascript"> var a=10; function get(){ alert(a); //undifined 因为在var a=2 javascript会默认在函数第一行里面进行声明 var a; var a=2; } alert(a); </script> </html>
4. php trait 可以执行多继承 -->use extend只可以单继承