1,Js 中各类型的常量表示形式: Number:number String:string Object:objec
2,typeof 运算符在 Js 中的使用: 用于判断某一对象是何种类型, 返回值是字符串 (各类型的常量的字符串形式)
- var message = "some string";
- alert((typeof message) == String)
- {
- alert("OK");
} -- 结果: false,ok
alert(typeof message == "string"); -true
3,typeof 不能精确的表示类的类型 (例如下面这个例子: 方法 Student 在这里首字母大写, 表明声明了一个类, 而使用 typeof 运算符时却打印出 object)
- function Student(n, a)
- {
- this.name = n;
- this.age = a;
- }
- var stuA = new Student('张三', 23);
- alert(typeof stuA)//object
- alert(stuA.name + ":" + stuA.age); // 张三: 23
- 4,
5, 对象的动态属性 (无中生有), 要求一定先声明一个对象然后再有该对象的动态相属性
6, 理解 Js 中函数的作用域 (importent)
- <script type="text/javascript">
- var color = "blue";//window.color
- function changeColor(){
- var anotherColor = "red";
- // 没有使用 var 关键字, 那么它的作用域是 Window, 所以永远不要这样写
- myColor = "yellow"; //window.myColor
- function swapColors(){
- var tempColor = anotherColor;
- anotherColor = color;
- color = tempColor;
- }
- swapColors();
- }
- changeColor();
- alert("Color is now" + color);//red
- alert(window.color); //red
- alert(window.myColor);//yellow
- </script>
来源: http://www.bubuko.com/infodetail-2580679.html