```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
// 繼承
var obj = {
a:1,
b:{
c:3
}
}
var obj1 = {
d:4
}
deepCopy(obj1, obj);
function deepCopy(target, source){
for(var k in source){
if(typeof source[k] == 'object'){
if(Array.isArray(source[k])){
target[k] = [];
}else{
target[k] = {};
}
deepCopy(target[k], source[k]);
}else{
target[k] = source[k];
}
};
}
</script>
</body>
</html>
```
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
// 繼承
var obj = {
a:1,
b:{
c:3
}
}
var obj1 = {
d:4
}
// new函數生成的對象可以訪問函數的prototype
// 對象是可以訪問他的__proto__
obj1.__proto__ = obj
console.log(obj1);
</script>
</body>
</html>
```
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
// 繼承
var obj = {
a:1,
b:{
c:3
}
}
// Object.create就相當于方法2 __proto__,但是更加清晰明了
var obj1 = Object.create(obj);
console.log(obj1);
</script>
</body>
</html>
```
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
// 繼承
function Animal(age, name) {
this.type = '動物';
this.age = age;
this.name = name;
}
Animal.prototype.getType = function (){
return this.type;
}
// 靜態屬性或者靜態方法
Animal.x = 1;
function Cat(age, name) {
// 執行他父親的構造函數,繼承了他的一些屬性
Animal.call(this, age, name);
}
Cat.prototype.say = function (){
console.log('喵喵!');
}
// 利用原型繼承父親的一些方法和屬性
// Cat.prototype.__proto__ = Animal.prototype;
// 跟上面代碼等價
Object.setPrototypeOf(Cat.prototype, Animal.prototype);
// Cat.__proto__ = Animal;
// 上下等價
Object.setPrototypeOf(Cat, Animal);
var c1 = new Cat(7, '加菲貓');
console.log(c1);
</script>
</body>
</html>
```
- 初級前端題
- 必會
- http協議
- 跨域
- cookie與storage
- 移動端問題
- 性能優化
- Vue全家桶
- 有哪些常用的es6語法?
- 項目
- 閉包
- JSON
- 數據類型與運算
- 數組
- DOM
- 字符串
- 要會
- async與await
- 正則
- this
- 數據加密
- 實時獲取數據
- 原生ajax
- 異步打印
- css相關
- 雜七雜八
- webpack
- 一般
- mvvm模式
- 異步請求
- XSS
- 其他dom問題
- 冷門
- 瀏覽器緩存機制
- 新
- 瀏覽器事件輪詢
- Promise
- 樹的深度優先與廣度優先
- 拷貝
- 繼承
- Vue
- 跨域
- 排序
- 瀏覽器
- 瀏覽器入門
- 瀏覽器內核知識
- 瀏覽器渲染原理
- 瀏覽器性能調優
- 自動化構建
- 字符編碼
- git
- 一些題目
- 其他
- 邏輯思維題
- 互聯網公司招聘信息如何閱讀
- bat面試