Lyrics


< More and better />


JS

跨域 域名、端口,协议相同,属于相同的域

  1. js可以使用jsonp进行跨域

  2. 通过修改document.domain来跨子域

  3. 使用window.name来进行跨域

基础细节

  1. 第一个字符必须是一个字母、下划线(_)或一个美元符号($);其他字符可以是字母、下划线、美元符号或数字。

js 继承

构造函数继承

1
2
3
4
5
6
7
8
function A(){
this.name='1'
}
function B (){
A.call(this)// 这样就是实现了 B的实例对象继承了A 的方法,但是不能实现继承A 原型上面的方法并没有真正的实现继承(部分继承) apply 也可以
}

最完美的继承方式,实现全部继承

1
2
3
4
5
6
7
8
9
10
11
12
function Parent4(){
this.name = "parent4";
this.colors = ["red","blue","yellow"];
}
Parent4.prototype.sex = "男";
Parent4.prototype.say = function(){console.log("Oh, My God!")}
function Child4(){
Parent4.call(this);
this.type = "child4";
}
Child4.prototype = Object.create(Parent4.prototype);
Child4.prototype.constructor = Child4;

es6 继承: extends
```

new 操作符

(1) 创建一个新对象;
(2) 将构造函数的作用域赋给新对象(因此 this 就指向了这个新对象) ;
(3) 执行构造函数中的代码(为这个新对象添加属性) ;
(4) 返回新对象。