浏览器模型和文档模型,js访问和操作浏览器的接口
Undefined、Null、Boolean、Number和String,Object
function构造函数创建Object
js判断对象、函数、和全局变量
typeof module === “object” && module && typeof module.exports === “object”
typeof define === “function” && define.amd
typeof window === “object” && typeof window.document === “object”
查看js类型,_proto_查看对象类型,typeof不能看到真实的类型
==和===的区别,==先做类型转换后比较,===直接比较
this调用源、self指向window全局变量// ES5构造函数
let Parent = function (name, age) {
this.name = name;
this.age = age;
};
Parent.prototype.sayName = function () {
console.log(this.name);
};
const child = new Parent('hello', 25);
child.sayName()
//ES6 class类
class Parent {
constructor(name, age) {
this.name = name;
this.age = age;
}
sayName() {
console.log(this.name);
}
};
const child = new Parent('echo', 25);
child.sayName() //echojs引擎单线程,浏览器是多线程的(ui渲染线程、http请求线程、js引擎线程等)
类似layui、vue、react等框架,js添加对commonjs和es6模块导出的支持,参考jquery的方式,成员放在函数中保证了代码的封装性
(function ($,fn) {
if ( typeof module === "object" && typeof module.exports === "object" ) {
module.exports = fn($)
} else {
fn($);
}
}($,function($){}))js中使用var的变量和函数都是全局的 函数中的变量对外不可见,相同函数名会覆盖前面的函数,和var作用域相同
typeof fn===“function”?fn():false