Skip to content

Commit

Permalink
note
Browse files Browse the repository at this point in the history
  • Loading branch information
abstain23 committed Dec 19, 2019
1 parent 79562c6 commit 34ef4f5
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
7 changes: 7 additions & 0 deletions less/ss.css
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;
}
12 changes: 12 additions & 0 deletions less/ss.less
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();
}

59 changes: 59 additions & 0 deletions 专题系列/深浅拷贝.html
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>
17 changes: 17 additions & 0 deletions 专题系列/类型判断.html
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>

0 comments on commit 34ef4f5

Please sign in to comment.