Vue学习--day1 前期准备

1、var块级是暴露在全局的,可重复声明(可覆盖值),存在变量提升。

2、let声明的变量,是块级作用域,不能重复声明。不存在变量提升(变量只能先定义后使用)。

3、const声明一个只读的变量,一旦声明,常量的值就不能改变。(一旦声明就必须初始化,不能等到以后赋值)

全部:

 

var b = [];
    for (var i = 0; i < 10; i++) {
        b[i]=function(){
            console.log(i);
        };
    }
b[6]();========结果为10


var b = [];
    for (let i = 0; i < 10; i++) {
        b[i]=function(){
            console.log(i);
        };
    }
b[6]();========结果为6

 

 

 

4、模板字符串,table键上面` ${}${} `

 

<script type="text/javascript">
    var a = '成功';
    var b = '失败';
    var str =`hahaha${a}heihei${b}`;
    alert(str)
</script>

 

 

 

5、箭头函数 var f = function(a){return a}     var f = a=>a

箭头函数中的this是定义时使用的对象(一般是window),不是箭头函数,一般是使用时定义的对象。 箭头 函数时arguments不好使

 

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<script>
    //箭头函数
    var f = function(){return 1};
    var ff =()=>2;
    alert(f());
    alert(ff());
    var f1=function(a,b){return a+b};
    var f11 = (a,b)=>a+b;
    alert(f1(1,2));
    alert(f11(1,3));
    var f2=()=>{
        console.log('cssdscscs')
    }
    f2()



</script>
</body>
</html>

 

 

 

6、对象的单体模式:fav(){}====fav:function(){}

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var c={
name:'alex',
age:18,
fav:function(){
// console.log('欧美国家')
console.log(this);
console.log(this.name);
}
}
c.fav();
var b={
name:'alex',
age:18,
fav:()=>{
// console.log('欧美')
console.log(this);
console.log(this.name);
}
}
b.fav();

var d={
name:'alex',
age:18,
fav(){
// console.log('欧美')
console.log(this);
console.log(this.name);
}
}
d.fav();
</script>
</body>
</html>

 

7、js面向对象

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<script type="text/javascript">
    function Animal(name,age){
        this.name=name;
        this.age = age;
    }
    Animal.prototype.shwoName=function(){
        console.log(this.name)
    }
    var a = new Animal('小黑','38')
    alert(a.name)
    alert(a.age)
    a.shwoName()


    class Animal{
        constructor(name,age){
            this.name = name;
            this.age =age;
        }
        shwoName(){
            console.log(this.name)
        }
    }
    var a = new Animal('小黑','30')
    console.log(a.name)
    console.log(a.age)
</script>
</body>
</html>

 

posted @ 2020-09-23 10:22  谭文章  阅读(137)  评论(0编辑  收藏  举报