首页 > 技术文章 > 8.25study

hudunyu 2020-08-25 09:47 原文

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box p{
      color: black;
    }
    div.text{
      color: red;
      width: 10px;
      box-sizing: border-box;
      padding: 3px;
    }
  </style>
  <script>
    this.b='2';
    function abc(){
      let b=1;
      ++b;
      setTimeout(()=>{
        test('fun test');
      },0);
      setTimeout(
        test('test fun'),1000
      );
      console.log(b);
      function test(str){
        console.log(this.b)
        this.b++;
        console.log(str);
        console.log(this.b)
        console.log(this.b++);
      }
    }
    abc();
  </script>
</head>
<body>
  <div class="box">
    <p class="text">Welcome to Hetl</p>
  </div>
</body>
</html>

  考察:

  1.下面文字的颜色与其所在盒子的实际宽度:'  red , 视图宽度

  2.js运行输出?

 2
 test fun
 3
 3
 2
 4
 fun test
 5
 5

  

  请实现如下语法功能:(5).plus(3).minus(2)=6; 

  考察点:链式调用;

Number.prototype.plus = function (num) {   // 注:箭头函数会将this指向window
	return this + num
}
Number.prototype.minus = function (num){
	return this - num
}
var a = (5).plus(3).minus(2);
console.log(a)

 

 

推荐阅读