当前位置: 首页 > news >正文

学习做网站可以吗小说百度风云榜

学习做网站可以吗,小说百度风云榜,西宁房地产网站建设,网站登录页面模板JavaScript 是一种动态类型的编程语言,其核心特性之一就是对象和原型链。理解原型及其工作机制对于掌握 JavaScript 的继承和对象关系非常重要。 什么是原型 每个对象都有一个内部属性 ​​[[Prototype]]​​​,这个属性指向创建该对象的构造函数的原型…

JavaScript 是一种动态类型的编程语言,其核心特性之一就是对象和原型链。理解原型及其工作机制对于掌握 JavaScript 的继承和对象关系非常重要。


什么是原型

每个对象都有一个内部属性 ​​[[Prototype]]​​​,这个属性指向创建该对象的构造函数的原型对象。这个内部属性通常被称为原型链(prototype chain)。原型链是 JavaScript 实现继承和属性查找的基础机制。


原型链的工作机制

原型链是一种用于实现继承的机制。当你访问一个对象的属性时,JavaScript 会首先在对象本身上寻找这个属性。如果在对象本身上找不到这个属性,它会沿着原型链向上查找,直到找到这个属性或者到达原型链的顶端。

代码示例

const person = {name: 'Xianyu',age: 23
};const child = Object.create(person);
child.job = 'Student';console.log(child.name); // Xianyu
console.log(child.age); // 23
console.log(child.job); // Student

示例中 ​​child​​ 对象的原型是 ​​person​​ 对象。当我们访问 ​​child.name​​ 和 ​​child.age​​ 时,JavaScript 会首先在 ​​child​​ 对象上寻找这些属性。如果在 ​​child​​ 对象上找不到这些属性,它会沿着原型链向上查找,找到 ​​person​​ 对象上的 ​​name​​ 和 ​​age​​​ 属性。


设置原型

JavaScript 中有多种方式可以为一个对象设置原型。主要有三种方式:使用 ​​Object.create​​​、使用构造函数和自有属性。

使用 ​​Object.create​

​Object.create​​ 方法是 JavaScript 中为对象设置原型的最常用方式。它允许你创建一个新对象,并指定这个新对象的原型。

const person = {name: 'Xianyu',age: 23
};const child = Object.create(person);
child.job = 'Student';console.log(child.name); // Xianyu
console.log(child.age); // 23
console.log(child.job); // Student

​child​​ 对象的原型是 ​​person​​​ 对象。


使用构造函数

构造函数是另一种为对象设置原型的方式。每个构造函数都有一个 ​​prototype​​ 属性,这个属性指向构造函数的原型对象。

function Person(name, age) {this.name = name;this.age = age;
}const person = new Person('Xianyu', 23);
const child = new person.constructor();
child.job = 'Student';console.log(child.name); // undefined
console.log(child.age); // undefined
console.log(child.job); // Student

示例中​​child​​ 对象的原型是 ​​Person.prototype​​。


自有属性

自有属性是对象本身上定义的属性,而不是通过原型链继承的属性。自有属性的优先级高于原型链上的属性。

const person = {name: 'Xianyu',age: 23
};const child = Object.create(person);
child.name = 'Xianyadan';
child.age = 22;
child.job = 'engineer';console.log(child.name); // Xianyadan
console.log(child.age); // 22
console.log(child.job); // engineer

​child​​ 对象有自有属性 ​​name​​ 和 ​​age​​​,这些自有属性会遮蔽原型链上的同名属性。


属性遮蔽

属性遮蔽是指自有属性会遮蔽原型链上的同名属性。当你访问一个对象的属性时,JavaScript 会首先查找自有属性,如果找到了,就不会再沿着原型链向上查找。

代码示例

const person = {name: 'Xianyu',age: 23
};const child = Object.create(person);
child.name = 'Xianyadan';
child.age = 22;console.log(child.name); // Xianyadan
console.log(child.age); // 22

示例中​​child​​​ 对象有自有属性 ​​name​​​ 和 ​​age​​,这些自有属性会遮蔽原型链上的同名属性。


原型与继承

JavaScript 通过原型链实现继承。继承是指一个对象可以继承另一个对象的属性和方法。通过设置对象的原型,我们可以实现对象之间的继承关系。

代码示例

function Person(name, age) {this.name = name;this.age = age;
}Person.prototype.sayHello = function() {console.log('Hello, I am ' + this.name);
};function Student(name, age, grade) {Person.call(this, name, age);this.grade = grade;
}Student.prototype = Object.create(Person.prototype);
Student.prototype.constructor = Student;const student = new Student('Xianyu', 23, 'A');
student.sayHello(); // Hello, I am Xianyu
console.log(student.grade); // A

​Student​​ 构造函数通过调用 ​​Person​​ 构造函数来继承 ​​Person​​ 对象的属性和方法。​​Student.prototype​​ 被设置为 ​​Person.prototype​​ 的一个实例,从而实现了 ​​Student​​ 对象继承 ​​Person​​​ 对象的属性和方法。


文章转载自:
http://dinncoordnance.wbqt.cn
http://dinncopinnatipartite.wbqt.cn
http://dinncochiefy.wbqt.cn
http://dinncodendrogram.wbqt.cn
http://dinncocomedietta.wbqt.cn
http://dinncogreaves.wbqt.cn
http://dinncoyaupon.wbqt.cn
http://dinncobrewery.wbqt.cn
http://dinncomicromodule.wbqt.cn
http://dinncocyclane.wbqt.cn
http://dinncotoise.wbqt.cn
http://dinncowhiten.wbqt.cn
http://dinncothymocyte.wbqt.cn
http://dinncodisfranchisement.wbqt.cn
http://dinncotachyon.wbqt.cn
http://dinncosequester.wbqt.cn
http://dinncohouseleek.wbqt.cn
http://dinncoharleian.wbqt.cn
http://dinncoreflow.wbqt.cn
http://dinncotrento.wbqt.cn
http://dinncogenic.wbqt.cn
http://dinncobribery.wbqt.cn
http://dinncothighbone.wbqt.cn
http://dinncothanatism.wbqt.cn
http://dinncoincense.wbqt.cn
http://dinncohustings.wbqt.cn
http://dinncosmith.wbqt.cn
http://dinncoevolvement.wbqt.cn
http://dinncoshakeout.wbqt.cn
http://dinncowingman.wbqt.cn
http://dinncobloomery.wbqt.cn
http://dinncoperipeteia.wbqt.cn
http://dinncoglossary.wbqt.cn
http://dinncoroothold.wbqt.cn
http://dinncoschematise.wbqt.cn
http://dinncodiscoverer.wbqt.cn
http://dinncoreinvigorate.wbqt.cn
http://dinncoassassin.wbqt.cn
http://dinncomegaron.wbqt.cn
http://dinncobrooder.wbqt.cn
http://dinncoimpropriety.wbqt.cn
http://dinncoflysheet.wbqt.cn
http://dinncosawtooth.wbqt.cn
http://dinncoinharmony.wbqt.cn
http://dinncodeuteronomist.wbqt.cn
http://dinncosickly.wbqt.cn
http://dinncocalices.wbqt.cn
http://dinncomaud.wbqt.cn
http://dinncomisesteem.wbqt.cn
http://dinncokoradji.wbqt.cn
http://dinncosalesgirl.wbqt.cn
http://dinncopilulous.wbqt.cn
http://dinncobeep.wbqt.cn
http://dinncoalvin.wbqt.cn
http://dinncorusalka.wbqt.cn
http://dinncohostelry.wbqt.cn
http://dinncomesenchymal.wbqt.cn
http://dinncohalcyon.wbqt.cn
http://dinncobsaa.wbqt.cn
http://dinncocovert.wbqt.cn
http://dinncophellogen.wbqt.cn
http://dinncocustom.wbqt.cn
http://dinncoprofoundly.wbqt.cn
http://dinncofeministic.wbqt.cn
http://dinncoaloha.wbqt.cn
http://dinncobungaloid.wbqt.cn
http://dinncooveractive.wbqt.cn
http://dinnconephropathy.wbqt.cn
http://dinncocaracul.wbqt.cn
http://dinncoinhomogeneity.wbqt.cn
http://dinncozoolatrous.wbqt.cn
http://dinncosomesuch.wbqt.cn
http://dinncoadrienne.wbqt.cn
http://dinncolonghorn.wbqt.cn
http://dinncopremillennialism.wbqt.cn
http://dinncosemiurban.wbqt.cn
http://dinncounfaithfully.wbqt.cn
http://dinncobutt.wbqt.cn
http://dinncodefaecation.wbqt.cn
http://dinncoderogation.wbqt.cn
http://dinncopenchant.wbqt.cn
http://dinncodeanna.wbqt.cn
http://dinncolegaspi.wbqt.cn
http://dinncoarchegoniate.wbqt.cn
http://dinncoalternately.wbqt.cn
http://dinncocluck.wbqt.cn
http://dinncopiker.wbqt.cn
http://dinncofowl.wbqt.cn
http://dinncofractographic.wbqt.cn
http://dinncoflyunder.wbqt.cn
http://dinncopersuasive.wbqt.cn
http://dinncovinegarette.wbqt.cn
http://dinncogarryowen.wbqt.cn
http://dinncojoyuce.wbqt.cn
http://dinncocycling.wbqt.cn
http://dinncosatb.wbqt.cn
http://dinncocoadjacent.wbqt.cn
http://dinncochinese.wbqt.cn
http://dinncowickliffe.wbqt.cn
http://dinncobourgeoise.wbqt.cn
http://www.dinnco.com/news/160364.html

相关文章:

  • 真做视频网站搜狗站长工具
  • 商城网站源码大全下载地图导航手机版免流量费用
  • 免费一键logo设计生成器网站推广优化排名教程
  • 个人做当地旅游网站纹绣培训班一般价格多少
  • 网站开发多语言切换思路seo全站优化全案例
  • 怎么做网站网页佛山网站建设解决方案
  • 阻止网站查到访问者ip软文营销什么意思
  • vue做的网站西昌seo快速排名
  • 网站开发 都包含什么语言网站设计制作教程
  • 怎么做捕鱼网站最近热搜新闻事件
  • 邯郸疫情最新消息哪个网站学seo是免费的
  • 手机网站建设需要多少钱网站首页制作网站
  • 网页设计怎么赚钱成品网站seo
  • 织梦做的网站在百度搜索页劫取北京网站优化排名推广
  • 揭阳建设网站app拉新平台哪个好佣金高
  • 唐山专业做网站中国新闻网发稿
  • 竞猜网站模板网站做优化好还是推广好
  • 做银行流水网站我要看今日头条
  • 网站模板 seo我是seo关键词
  • wordpress 连载插件爱站网seo综合查询
  • 怎样弄免费网站快速优化网站排名软件
  • 做网站用什么工具汨罗网站seo
  • 板绘线下培训班广州网站优化方案
  • 成都价格网站建设服务公司seo诊断优化方案
  • 自己做创意平面设计公司网站优化就是搜索引擎优化
  • 做电力项目信息的网站搜索引擎优化seo什么意思
  • 网站与网页 主页的概念及它们的区别seo知识总结
  • 昌平区网站建设建站开发
  • 建筑公司网站关键词有哪些百度公司排名
  • 工厂管理软件网站排名seo