javascript

<script src="/static/test.js"></script>

严格区分大小写

数据类型:Number,String,Boolean,Null,Undefined,数组,对象

==转类型再比,===直接比(建议)

NaN不等于任何,isNaN(NaN)判断,

浮点数比较用绝对值小于来比,防止误差,

null表示不存在的空,undefined表示没有定义值,0,''空字符串

js对象是键值对集合,键字符串,值任意,

模板字符串``换行,放变量

单独修改字符串的某个字符是无效的

字符串s.indexOf('haha') s.substring(2,5) s.substring(5)

数组arr.indexOf('hello') arr.slice(3,5) arr.slice(5) push() pop() unshift() shift() sort() reverse() splice(a,b,c,d,f) arr.concat() arr.join('-') 

对象 ‘name’ in 对象   for in循环  m.set(key,value) m.delete(key) m.has(key) m.get(key)

null,undefined,0,'',NaN一律为false

 map类型同对象, set类型,s.add(key),s.delete(key)

iterable类型:array,map,set,  

数组遍历arr.forEach(function(element,index,array){})   for of适合遍历数组,for in适合遍历对象

函数arguements函数内表示传入参数类似数组   ...rest 表示任意参数类似数组

变量定义提升,赋值不提升

let const块级作用域,

解构赋值

this 指针 apply()  call()

高阶函数arr.map(一个参数的函数变量)返回一个数组   arr.reduce(两个参数的函数变量) arr.filter(一到三个参数的函数变量)//(元素,索引,本身数组)用于筛选

    arr.sort()默认转变为字符串后进行ASCII排序,且原来的数组也会被直接修改,可以手动控制sort(function(x,y){return -1,0,1})

闭包 

  匿名函数立刻执行 (function(x){return x*x;})(5)

箭头函数

  箭头函数的this永远指向定义时的环境

generator生成器

  yield返回多个,记录执行状态的函数

 标准对象(廖雪峰老师)

  • 不要使用new Number()new Boolean()new String()创建包装对象;

  • parseInt()parseFloat()来转换任意类型到number

  • String()来转换任意类型到string,或者直接调用某个对象的toString()方法;

  • 通常不必把任意类型转换为boolean再判断,因为可以直接写if (myVar) {...}

  • typeof操作符可以判断出numberbooleanstringfunctionundefined

  • 判断Array要使用Array.isArray(arr)

  • 判断null请使用myVar === null

  • 判断某个全局变量是否存在用typeof window.myVar === 'undefined'

  • 函数内部判断某个变量是否存在用typeof myVar === 'undefined'

  • number对象调用toString()报SyntaxError     123..toString()或(123).toString()

 Date对象

  var now = new Date();

  now; // Wed Jun 24 2015 19:49:22 GMT+0800 (CST)
  now.getFullYear(); // 2015, 年份
  注意:now.getMonth(); // 5, 月份,注意月份范围是0~11,5表示六月
  now.getDate(); // 24, 表示24号
  now.getDay(); // 3, 表示星期三
  now.getHours(); // 19, 24小时制
  now.getMinutes(); // 49, 分钟
  now.getSeconds(); // 22, 秒
  now.getMilliseconds(); // 875, 毫秒数
  now.getTime(); // 1435146562875, 以number形式表示的时间戳

 正则表达式

  • 清晰的廖雪峰老师:https://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/001434499503920bb7b42ff6627420da2ceae4babf6c4f2000

 JSON

  JSON.stringify()化成json字符串  JSON.parse()化成json对象操作格式

面向对象编程

  • s=Object.create(Student)   原型继承
  • 一条原型链
  • 构造函数
    • function Student(name){
      this.name=name;
      this.hello=function(){alert('hello'+this.name)}
      }
    • let studentOne=new Student('nameOne');
    • studentOne->Student.prototype->Object.prototype->null
    • 原型对象是构造函数的一个实例,且被之后的所继承
    • es6   class Student(){
        constructor(name){this.name=name}
             hello(){alert('hello')}
      }
                class Person extends Student{
            constructor(name,grade){super(name);this.grade=grade;}
           hi(){alert('hi')}
      }

 浏览器对象

  • window全局作用域,浏览器窗口
    • window.innerWidth
    • windows.innerHeight 
    • windows.outerWidth 
    • windows.outerHeight
  • navigator
    • navigator.appName
    • navigator.appVersion
    • navigator.language
    • navigator.platform
    • navigator.userAgent
  • screen
    • screen.width
    • screen.height
    • screen.colorDepth
  • location
    • location.href
    • location.protocol
    • location.host
    • location.port
    • location.pathname
    • location.search
    • location.hash
    • location.assign()
    • location.reload()
  • document
    • document.title
    • documne.cookie
    • document.getElementById()
    • document.getElementByClassName()
    • document.getElementByTagName()
  • history

DOM

    • document.getElementById()
    • document.getElementsByTagName()
    • document.getElementsByClassName()
    • document.querySelector('')
    • document.querySelectorAll('')
    • p.innerHTML
    • p.innerText
    • p.innerContent
    • p.style.css(驼峰命名法)
    • list.appendChild(js)//list节点的子节点的最后插入js节点
    • var d=document.createElement('p')
    • list.insertBefore(position,js)//js插入position之前
    • list.children//子节点数组
    • parent = js.parentElement//父元素
    • left=parent.removeChild(js);

 表单

  • 文本框<input type="text">
  • 密码框<input type="password">
  • 单选框<input type="radio">
  • 复选框<input type="checkbox">
  • 下拉框<select>
  • H5新元素
  • 文件<input type="file">

Promise

  • 串行执行异步
  • 并行执行异步

 

posted @ 2018-01-12 21:30  王利群  阅读(131)  评论(0)    收藏  举报