-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.border { | ||
border: 1px solid red; | ||
} | ||
#menu a { | ||
color: #111; | ||
border: 1px solid red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@width: 10px; | ||
@height: @width +10px; | ||
|
||
.border { | ||
border: 1px solid red; | ||
} | ||
|
||
#menu a { | ||
color: #111; | ||
.border(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!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>深浅拷贝</title> | ||
</head> | ||
<body> | ||
<script> | ||
//数组的浅拷贝 | ||
// concat slice | ||
|
||
var arr = [{old: 'old'}, ['old']]; | ||
|
||
var new_arr = arr.concat(); | ||
|
||
arr[0].old = 'new'; | ||
arr[1][0] = 'new'; | ||
|
||
console.log(arr) // [{old: 'new'}, ['new']] | ||
console.log(new_arr) // [{old: 'new'}, ['new']] | ||
|
||
//数组的深拷贝 | ||
var arr = ['old', 1, true, ['old1', 'old2'], {old: 1}] | ||
|
||
var new_arr = JSON.parse( JSON.stringify(arr) ); //不能用于拷贝函数 | ||
|
||
|
||
//浅拷贝的实现 | ||
|
||
var shallowCopy = function(obj) { | ||
if(typeof obj !== 'object') return | ||
|
||
var newObj = obj instanceof Array ?[]:{} | ||
for(var key in obj){ //会遍历原型上的对象 | ||
if(obj.hasOwnproperty(key)){ //只有是自身的才可行 | ||
newObj[key] = obj[key] | ||
} | ||
} | ||
return newObj | ||
} | ||
|
||
|
||
//深拷贝的实现 | ||
|
||
var deepCopy = function(obj) { | ||
if(typeof obj !== 'object') return | ||
var newObj = obj instanceof Array ? [] : {} | ||
for(var key in obj){ | ||
if(obj.hasOwnproperty(key)){ | ||
newObj[key] = typeof obj[key] === 'object' ? deepCopy(obj[key]) : obj[key] | ||
} | ||
} | ||
return newObj | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!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>专题之类型判断</title> | ||
</head> | ||
<body> | ||
<script> | ||
//Object.prototype.toString | ||
function typeClass(obj){ | ||
return Object.prototype.toString.call(obj).slice(8,-1).toLocaleLowerCase() | ||
} | ||
</script> | ||
</body> | ||
</html> |