ES6部分
1.块及作用域
let:块级变量
const:常量,与var相对应。
结构赋值
2.数组:
map(),reduce()
3.generator:分步执行
function*
里面return无效。
4.优化回调函数
原生JS部分
原型链:js中每个函数都有一个指向某一对象的prototype属性,当改函数被new操作符调用时会创建并返回一个对象,该对象会有一个指向原型对象的秘密连接(__proto__),通过该属性我们可以在新建的对象中调用原型对象的方法和属性。
__proto__属性IE不支持,需要使用prototype属性。
document.nodeType,返回节点类型。
document对象的documentElement属性返回根节点(html标签)。
document.documentElement.nodeName和document.documentElement.tagName返回标签名。
document.documentElement.hsaChildNodes();检查一个节点是否有子节点。
document.documentElement.ChildNodes.length;返回子节点长度。
document.documentElement.ChildNodes[0];返回第一个子节点。
object.hasAttribute(),检查元素中是否具有某属性。
object.getAttribute(),获取某属性的属性值。
object.attributes.length,返回属性的数量
访问DOM节点的方法:
老:getElementById,getElementsByName,getElementsByTagName
新:getElementsByClassName,querySelector,querySelectorAll
兄弟节点:nextSibling,previousSibling
子节点;firstChild,lastChild
添加节点:appendChild,insertBefore,replaceChild
移除节点:removeChild
函数对象的call和apply方法,让一个对象去借用另一个对象的方法为己所用,这样就能做到代码重用了。
func2.call(func1,prama1,prama2,prama3)
func2.call(func1,[prama1,prama2,prama3])
function Person(name,age)...{ //定义一个类,人类
this.name=name //名字
this.age=age //年龄
this.sayhello=function()...{alert("hello")}
}
function Print()...{ //显示类的属性
this.funcName="Print"
this.show=function()...{
var msg=[]
for(var key in this)...{
if (typeof(this[key])!="function") msg.push([key,":",this[key]].join(""))
}
alert(msg.join(" "))
}
}
function Student(name,age,grade,school)...{ //学生类
Person.apply(this,arguments)
Print.apply(this,arguments)
this.grade=grade //年级
this.school=school //学校
}
var p1=new Person("jake",10)
p1.sayhello()
var s1=new Student("tom",13,6,"清华小学")
s1.show()
s1.sayhello()
alert(s1.funcName)
构造器属性(constractor):该属性指向用于创建该对象的构造器函数的引用。
instanceof操作符:测试一个对象是不是由某个构造器函数创建的。
原型属性(prototype):可以给对象添加属性和方法。
obj.prototype.attr = value;
obj.prototype.func = function(){};
isPrototypeOf()方法:判断当前对象是否是另一个对象的原型。
__proto__:对象中存在的指向相关原型的链接。
原型链:原型对象本身包含了指向其原型的链接,多个指向连在一起就形成了原型链。
Object.create();原型继承
Object.create(proto [, propertiesObject ]) 是E5中提出的一种新的对象创建方式,第一个参数是要继承的原型,如果不是一个子函数,可以传一个null,第二个参数是对象的属性描述符,这个参数是可选的。