javascript学习笔记之javascript类型

    //全局变量不能采用delete删除
    var age1 = '29';
    var a = delete window.age1;
    window.sss = 'b';
    var b = delete window.sss;
    console.log(a + window.age1);//返回false
    console.log(b + window.sss);//b 为true,成功删除
//    var old = value; //会出现错误提示
    var old = window.value;//undefined但是不报错

    //window的frame访问机制
    var left = (typeof window.screenX == 'number')?window.screenX:window.screenLeft;
    var top = (typeof window.screenY == 'number')?window.screenY:window.screenTop;
    console.log('left' + left);
    console.log('right' + top);

    //moveTo()\moveBy()方法,可能被浏览器禁用。
    console.log(window.innerHeight);//浏览器高度
    console.log(window.outerHeight);//视图高度
    console.log(window.innerWidth);//浏览器宽度
    console.log(window.outerWidth);//视图宽度
//    console.log(document.body.clientWidth);
//    console.log(document.body.clientHeight);
    console.log(document.documentElement.clientWidth);//移动端显示渲染后页面的大小,而非视图的大小
    console.log(document.documentElement.clientHeight);
    //调整窗口的大小,默认被禁用,只适用于最外层window对象
    resizeTo(100,100);
    resizeBy(100,50);

    //打开窗口,如果浏览器屏蔽了打开窗口会返回null
    var open1 = window.open('open.html','my','fullScreen=true,location=false,toolbar=yes',true);
    open1.resizeTo(500,500);//规定大小
    open1.moveTo(100,100);//移动
    open1.close();//关闭
    console.log(open1.closed);//验证是否关闭
    console.log(open1.opener);
//    open1.opener = null; 切断与打开标签之间的联系

    //超时调用函数,在1000ms后,将其加入任务队列,
    // 由于是单线程的,所以当队列为空时立即执行,如果不为空,则需要等待
    var myTime = setTimeout(function(){
        alert("hello world!");
    },1000);

    //取消超时函数调用,
    clearTimeout(myTime);
    //超时循环调用
    var myInter = setInterval(function(){
        alert('running');
    },1000);
    clearInterval(myInter);

    //对话框
    alert('hello');
    var result = confirm('hello');//点击ok按钮返回true,cancel返回false
    var input = prompt('what is your name?','Andy');
    console.log(input);//点击了取消的话,返回null
//    window.print();//打印对话框
//    window.find();//查找对话框

    //location
   // location.assign('file:///C:/Users/JNC/Desktop/test.html');
    //与window.location和location.href是相同的效果,链接跳转
    //location.hash
    //location.search
    //location.port hostname pathname
    //如过要禁止页面的回退行为,用location.replace()
   // location.reload();//可能从浏览器缓存中重新加载
  // location.reload(true);//强制从服务器重新加载

//    navigate对象
       //1.检测插件plugins
    function has(plugin){
        plugin = plugin.toLowerCase();
        console.log(navigator.plugins);
        for(var i =0;i<navigator.plugins.length;i++){
            if(navigator.plugins[i].toLowerCase().indexOf(plugin)>-1){
                return true;
                console.log(navigator.plugins[i].toLowerCase());
            }
        }
        return false;
    }
    console.log(has('flash'));

1、null类型:null!=object、null == undefined,由于undefined类派生自null类,因此null==undefined 结果为true

2、子页面iframe:iframe区域支持双向调用

3、javascript全局函数有13个:

编码解码方面的:
1、decodeURI()、
2、encodeURI()、
3、decodeURIComponent()
4、encodeURIComponent()
5、escape()、
6、unescape()

表达式计算:1、eval()
判断变量类型:
1、isFinite(number)无限大
2、isNaN()是否是数字
 3、Number()非数字返回NaN
4、parseFloat()
5、parseInt()
6、String()

4、变量的存放位置:堆区存放较大的临时变量、栈区存放较小的临时变量、代码区存放代码、全局区存放静态变量

5、javascript中的this:

全局
函数作为对象方法时,this指向该对象
原型链上的可指向对象
构造器
    function f(){
        this.a = 37;
        return {a:38};
    }
    function b(){
        c = new f();
        alert(c.a);
        alert(this.a);
    }
此时第一个this赋值指向的也并非全局
指定函数中的this可以选择all或者apply
blind支持IE9+

6、typeof不是函数,而是操作符。

7、严格模式,八进制无效。

			'use strict'
			var message;
			alert(message);
			//alert(a);//Uncaught ReferenceError: a is not defined,会出现此错误提示
			alert(typeof(a));//非严格模式下,虽未声明的变量delete不会报错,只是无意义而已
			delete(a);//严格模式下Uncaught SyntaxError: Delete of an unqualified identifier in strict mode.

8、浮点数精度问题:浮点数的最高精度是17位小数,但是计算精确度不如整数,请注意:

var a = 0.1;
var b = 0.2;
alert(a + b == 0.3);//false
Number.MIN_VALUE:3e-324
Number.MAX_VALUE:1.7E304

9、infinity 无穷大 isFinity()函数
10、NaN 非0数值,注意NaN与NaN本身不相等判断 isNaN()

11、number()函数,可将任何类型的变量转为数字、浮点数或者NaN

parseInt()忽略空格,知道找到第一个非空格字母,若不是数字或正负号返回NaN,对空字符串返回NaN,与number()不同。

parseFloat()只解析十进制数据,16进制将返回0

12、用var age形式定义的变量不能用delete删除
而window.age形式的则可以。由于属性的[[configurable]]被设置为false
13、窗口位置属性,在IE、Safari、opera、和chrome中有screenLeft和screenTop,在Firefox中有screenX,screenY



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值