1 Star 0 Fork 0

铃酱是男生/js基础代码学习

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
constructor.html 3.04 KB
一键复制 编辑 原始数据 按行查看 历史
铃酱是男生 提交于 2022-06-28 02:46 . 第一次提交
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// function Person(name, age, gender) {
// this.name = name
// this.age = age
// this.gender = gender
// this.sayName = function () {
// alert(this.name);
// }
// }
// var per = new Person("孙悟空", 18, "男");
// var per2 = new Person("猪八戒", 20, "男")
// function Dog(name, age, gender) {
// this.name = name
// this.age = age
// this.gender = gender
// }
// var dog = new Dog("旺财", 4, "雄")
// console.log(per);
// //当我们直接在页面中打印一个对象时,事件上是输出的对象的toString()方法的返回值
// console.log(per2);
// console.log(dog);
class Parent {
constructor(name) {
this.name = name;
}
}
class Child extends Parent {
constructor(name, age) {
super(name);
this.age = age;
}
}
const child = new Child("xiaohua", 18)
// console.log(Child);
// console.log(child.__proto__);
// console.log(child.__proto__.__proto__);
// console.log(Parent.prototype);
// console.log(Parent.prototype.prototype);
// function Animal(name, age) {
// this.name = name;
// this.age = age;
// }
// Animal.prototype.eat = function () {
// console.log('吃吃吃')
// }
// var dog = new Animal('狗狗', 12)
// console.log('-----dog-----');
// console.log(dog);
// console.log('constructor', dog.constructor);
// console.log('pro', dog.__proto__);
// console.log('pro.pro', dog.__proto__.__proto__);
// console.log('pro.pro.pro', dog.__proto__.__proto__.__proto__);
// console.log('--------------');
// console.log('--------------');
// console.log('-----Animal-----');
// console.log(Animal);
// console.log('constructor', Animal.constructor);
// console.log('prot', Animal.prototype);
// console.log('prot.pro', Animal.prototype.__proto__);
// console.log('prot.pro.pro', Animal.prototype.__proto__.__proto__);
// 原型链的使用
function People (name, age) {
this.name = name;
this.age = age;
}
function Student(name ,age) {
this.name = name;
this.age = age;
console.log(this);
this.sayHi = function () {
console.log('内部 Hello, I am ' + this.name + " , nice to meet you!");
}
}
Student.prototype.sayHi = function() {
console.log('Hello, I am ' + this.name + " , nice to meet you!");
}
Student.prototype.read = function(bookName) {
console.log('I am reading 《' + bookName + "》.");
}
let nick = new Student('Nick', 15);
console.log(nick);
nick.sayHi()
nick.read('西游记');
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ling0512/js-basic-code-learning.git
git@gitee.com:ling0512/js-basic-code-learning.git
ling0512
js-basic-code-learning
js基础代码学习
master

搜索帮助