forked from Vacricticy/JS_Advanced
-
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
1 parent
41d4539
commit 08fdac5
Showing
19 changed files
with
138 additions
and
16 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,30 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
|
||
<body> | ||
<script> | ||
// 方式一:通过new Object()创建对象 | ||
var obj = new Object() | ||
// 方式二:通过对象字面量创建对象 | ||
var obj2 = {} | ||
// 方式三:通过构造函数创建对象 | ||
// 构造函数的首字母要大写 | ||
function Star(name, age) { | ||
this.name = name; | ||
this.age = age; | ||
this.sing = function() { | ||
console.log(this.name + 'sing a song'); | ||
} | ||
} | ||
var adele = new Star('阿黛尔', 20) | ||
adele.sing() | ||
</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,31 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
|
||
<body> | ||
<script> | ||
function Star(name, age) { | ||
// 实例成员是指通过this添加的成员 | ||
this.name = name; | ||
this.age = age; | ||
this.sing = function() { | ||
console.log(this.name + 'sing a song'); | ||
} | ||
} | ||
var adele = new Star('阿黛尔', 20) | ||
console.log(adele.name); //实例成员只能通过实例对象访问 | ||
console.log(Star.name); | ||
|
||
// 静态成员是指在构造函数本身添加的成员 | ||
Star.sex = '女' | ||
console.log(Star.sex); //静态成员只能通过构造函数访问 | ||
console.log(adele.sex); | ||
</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,35 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
|
||
<body> | ||
<script> | ||
function Star(name, age) { | ||
this.name = name; | ||
this.age = age; | ||
// 1.若函数定义再构造函数内部,则每一个创建出来的对象都会其单独开辟内存地址空间。存在浪费地址空间的问题。 | ||
// this.sing = function() { | ||
// console.log(this.name + 'sing a song'); | ||
// } | ||
} | ||
// 2.每一个构造函数都有一个原型对象,在原型对象上定义属性可以实现所有对象共享该属性,即共享同一块地址空间。 | ||
Star.prototype.sing = function() { | ||
console.log(this.name + 'sing a song'); | ||
} | ||
var adele = new Star('阿黛尔') | ||
var wf = new Star('王菲') | ||
console.log(adele.sing()); | ||
console.log(wf.sing()); | ||
console.log(adele.sing === wf.sing); | ||
// console.dir(Star); | ||
|
||
// 3.❤一般情况下,公共属性定义在构造函数中,而公共方法定在在原型对象上 | ||
</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 @@ | ||
### 类的定义是在es6才出现的,在es6之前对象的创建是通过构造函数和原型来实现的 |