js知识点总结

1.js延迟加载的方法
1)放在之前,这样会页面显示完之后加载;
2)加上defer(延迟加载)和async(和文档并行加载)标识,不是所有的浏览器都支持;
3)onload chrom,opera,firefox;
4)onreadystatechange ie
http://blog.csdn.net/newborn2012/article/details/17057759

2.基本数据类型
1)number
2)string
3)boolean
4)null
5)undefined
6)object

3.1-100的随机数组(不重复)

var arr=new Array();
for(var i=0;i<100;i++){
    arr[i]=i+1;
}
arr.sort(fucntion(){
    return 0.5-Math.random();
});

4.

function a(xx){
    this.x = xx;
    return this; //指向了window
}
 var x = a(5);
 var y = a(6);
 console.log(x.x);//undefined
 console.log(y.x);//6

5.typeof 和 instanceof 的作用和区别
推荐链接
http://blog.csdn.net/mevicky/article/details/50353881

typeof 会返回一个变量的基本类型 有number,string,boolean,object,undefined,function
alert(typeof(10));//number
alert(typeof("string"));//string
alert(typeof(true));//boolean
alert(typeof(foo));//undefined
var obj=new Object();
var arr=[1,2,3]; //object   创建一个数组对象
var obj2={};//object
alert(typeof(obj));//object
function fun(){
//
} 
alert(typeof(fun))
****
无法区分是数组还是对象,所以可以用: 
1、constructor属性来区分 这个属性在我们使用js系统或者自己创建的对象的时候,会默认的加上,
例如: 
arr.prototype.constructor = Array;  //这一句是系统默认加上的 所以我们就可以这样来判断: 
alert(arr.constructor === Array);  // true
2.instanceof
arr instanceof Aarray //true
3.
function isArrayFn(obj){  //封装一个函数
    if (typeof Array.isArray === "function") { 
            return Array.isArray(obj); 
            //浏览器支持则使用isArray()方法
    }else{ //否则使用toString方法
            return Object.prototype.toString.call(obj) === "[object Array]"; 
    } 
} 
alert(isArrayFn(arr)); //true
****
instanceof 返回的是一个布尔值
obj instanceof Object //true
arr instanceof Object/Aarray //true

需要注意的是,instanceof只能用来判断对象和函数,不能用来判断字符串和数字等
var s='123';
s instanceof String //false
10 instanceof Number //false
var ss=new String('string');
ss instanceof String //true
typeof(ss); //"object" 或者 typeof ss //"object"

6.原型与原型链;
7.作用域与作用域链;
8.什么是闭包以及闭包Closures

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值