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

网站开发已有的知识储备友情链接交换标准

网站开发已有的知识储备,友情链接交换标准,做网站收费 知乎,衡东建设局网站在 JavaScript 中,每个对象都有一个关联的原型(prototype)。原型是一个对象,其他对象可以通过原型实现属性和方法的继承。原型链是一种由对象组成的链式结构,它通过原型的引用连接了一系列对象,形成了一种继…

在 JavaScript 中,每个对象都有一个关联的原型(prototype)。原型是一个对象,其他对象可以通过原型实现属性和方法的继承。原型链是一种由对象组成的链式结构,它通过原型的引用连接了一系列对象,形成了一种继承关系。

原型(Prototype):

每个 JavaScript 对象都有一个原型对象,它用于查找对象的属性和方法。对象可以通过 __proto__ 属性访问它的原型。在 ES6 中,可以使用 Object.getPrototypeOf() 方法获取对象的原型。

const myObject = {};
const myPrototype = Object.getPrototypeOf(myObject);console.log(myPrototype === Object.prototype);  // 输出: true

原型链(Prototype Chain):

原型链是一种对象之间通过原型引用连接起来的链式结构。当我们访问一个对象的属性或方法时,JavaScript 引擎首先在该对象本身查找,如果找不到,则会沿着原型链向上查找,直到找到对应的属性或方法,或者查找到达原型链的顶端(Object.prototype)。

function Animal(name) {this.name = name;
}Animal.prototype.sayHello = function() {console.log(`Hello, I'm ${this.name}`);
};const cat = new Animal('Whiskers');
cat.sayHello(); // 输出: Hello, I'm Whiskers

在上述例子中,cat 对象的原型是 Animal.prototypeAnimal.prototype 的原型是 Object.prototype。因此,当调用 sayHello 方法时,JavaScript 引擎首先在 cat 对象中查找,找不到的话就沿着原型链向上查找,最终在 Animal.prototype 中找到了 sayHello 方法。

原型链的终点:

原型链的终点是 Object.prototype,它是所有对象的根原型。Object.prototype 没有自己的原型,形成了原型链的终点。

构造函数与原型链:

通过构造函数创建的对象共享同一个原型。当我们创建一个新对象时,它的原型会指向构造函数的原型对象。

function Car(make, model) {this.make = make;this.model = model;
}Car.prototype.drive = function() {console.log('Vroom!');
};const myCar = new Car('Toyota', 'Camry');
myCar.drive(); // 输出: Vroom!

在上述例子中,myCar 对象的原型是 Car.prototype,而 Car.prototype 的原型是 Object.prototype,形成了原型链。

继承与原型链:

通过原型链,可以实现对象之间的继承。一个对象可以继承另一个对象的属性和方法,从而减少代码冗余。

function Bird(name) {this.name = name;
}Bird.prototype.fly = function() {console.log(`${this.name} is flying.`);
};function Penguin(name) {Bird.call(this, name);
}Penguin.prototype = Object.create(Bird.prototype);
Penguin.prototype.constructor = Penguin;Penguin.prototype.swim = function() {console.log(`${this.name} is swimming.`);
};const penguin = new Penguin('Happy Feet');
penguin.fly();  // 输出: Happy Feet is flying.
penguin.swim(); // 输出: Happy Feet is swimming.

在上述例子中,Penguin 构造函数通过 Bird.call(this, name) 继承了 Bird 构造函数的属性。然后,通过 Object.create(Bird.prototype) 创建了一个新对象,将其设置为 Penguin.prototype,从而继承了 Bird.prototype 中的方法。最后,将 Penguin.prototype.constructor 设置为 Penguin,确保正确指向构造函数。这样,Penguin 对象就能够继承 Bird 对象的方法。

Vue进阶:

在 Vue.js 2 中,原型链主要用于两个方面:全局方法和实例属性的访问。

1. 全局方法的访问:

Vue.js 在其原型链上定义了一些全局方法,可以通过实例对象或者全局引用来调用。例如,$emit$on 等方法。

// 在组件中使用
export default {methods: {handleClick() {this.$emit('custom-event', 'Hello from child!');}}
};// 在全局使用
Vue.prototype.$myGlobalMethod = function() {console.log('This is a global method!');
};// 然后在任何组件中
this.$myGlobalMethod();

2. 实例属性的访问:

在 Vue.js 2 中,实例对象上有一些特定的属性,可以通过原型链访问。

// 创建 Vue 实例
const vm = new Vue({data: {message: 'Hello, Vue!'}
});// 访问实例的属性
console.log(vm.$data.message); // 输出: Hello, Vue!

上述代码中,vm.$data.message 中的 $data 就是通过原型链访问到实例对象的属性。同样,还有其他一些实例属性,如 $props$el$options 等,它们可以提供对实例的不同方面的访问。

总的来说,原型链在 Vue.js 2 中主要用于提供全局方法和实例属性的访问。这样的设计使得在组件中可以方便地使用一些全局方法,同时也让开发者能够通过实例对象访问一些特定的实例属性。


文章转载自:
http://dinncoindigotin.ydfr.cn
http://dinncotimepiece.ydfr.cn
http://dinncohyperthyroidism.ydfr.cn
http://dinncoinferno.ydfr.cn
http://dinncoharmlessly.ydfr.cn
http://dinncophilae.ydfr.cn
http://dinncotranq.ydfr.cn
http://dinncosuperfecundation.ydfr.cn
http://dinncointerpol.ydfr.cn
http://dinncocalvinism.ydfr.cn
http://dinncofarthing.ydfr.cn
http://dinncoquasar.ydfr.cn
http://dinncoargosy.ydfr.cn
http://dinncopaedagogue.ydfr.cn
http://dinncoakureyri.ydfr.cn
http://dinncoallodium.ydfr.cn
http://dinncoendometria.ydfr.cn
http://dinncoguid.ydfr.cn
http://dinncodandriff.ydfr.cn
http://dinncosiphonic.ydfr.cn
http://dinncoremora.ydfr.cn
http://dinncochangchun.ydfr.cn
http://dinncohagseed.ydfr.cn
http://dinncosynanthy.ydfr.cn
http://dinncodistraint.ydfr.cn
http://dinncohematophagous.ydfr.cn
http://dinncokantele.ydfr.cn
http://dinncohavildar.ydfr.cn
http://dinnconaris.ydfr.cn
http://dinncogummous.ydfr.cn
http://dinncoviewership.ydfr.cn
http://dinncoresid.ydfr.cn
http://dinncofonda.ydfr.cn
http://dinncokilodyne.ydfr.cn
http://dinncodrylot.ydfr.cn
http://dinncoasynapsis.ydfr.cn
http://dinncopunctated.ydfr.cn
http://dinncoplaypit.ydfr.cn
http://dinncoenunciator.ydfr.cn
http://dinncooxherd.ydfr.cn
http://dinncosapporo.ydfr.cn
http://dinncojello.ydfr.cn
http://dinncohighjacking.ydfr.cn
http://dinncoslup.ydfr.cn
http://dinncorediffusion.ydfr.cn
http://dinncometeorograph.ydfr.cn
http://dinncowallpaper.ydfr.cn
http://dinncointerminable.ydfr.cn
http://dinncomonophonic.ydfr.cn
http://dinncogemel.ydfr.cn
http://dinncoviolence.ydfr.cn
http://dinncoinflammatory.ydfr.cn
http://dinncokootenay.ydfr.cn
http://dinncocircumrotate.ydfr.cn
http://dinncodermatologic.ydfr.cn
http://dinncoquadrangled.ydfr.cn
http://dinncodiene.ydfr.cn
http://dinncoacquittal.ydfr.cn
http://dinncodiscardable.ydfr.cn
http://dinncocompassionate.ydfr.cn
http://dinncomegaera.ydfr.cn
http://dinncoantiestrogen.ydfr.cn
http://dinncocms.ydfr.cn
http://dinncocarbuncle.ydfr.cn
http://dinncodiscolorment.ydfr.cn
http://dinncoillegimate.ydfr.cn
http://dinncopersona.ydfr.cn
http://dinncoparader.ydfr.cn
http://dinncojaw.ydfr.cn
http://dinncowhippy.ydfr.cn
http://dinncoyi.ydfr.cn
http://dinncocentered.ydfr.cn
http://dinncophilosophism.ydfr.cn
http://dinncobled.ydfr.cn
http://dinncoaglint.ydfr.cn
http://dinncosamadhi.ydfr.cn
http://dinncogunrunner.ydfr.cn
http://dinncokaanga.ydfr.cn
http://dinncoappassionato.ydfr.cn
http://dinncogibbous.ydfr.cn
http://dinncoclackmannanshire.ydfr.cn
http://dinncoluminosity.ydfr.cn
http://dinncoverminosis.ydfr.cn
http://dinncotriglyceride.ydfr.cn
http://dinncocatechist.ydfr.cn
http://dinncomonotheistic.ydfr.cn
http://dinncoerivan.ydfr.cn
http://dinncoconvoke.ydfr.cn
http://dinncovitaphone.ydfr.cn
http://dinncodemarch.ydfr.cn
http://dinncoopportunity.ydfr.cn
http://dinncophosphopyruvate.ydfr.cn
http://dinncotenderee.ydfr.cn
http://dinncofreaky.ydfr.cn
http://dinncocannister.ydfr.cn
http://dinncopagurid.ydfr.cn
http://dinncomoribund.ydfr.cn
http://dinncoupc.ydfr.cn
http://dinncolocational.ydfr.cn
http://dinncoguileless.ydfr.cn
http://www.dinnco.com/news/119608.html

相关文章:

  • 个人网站实现与设计论文百度推广价格价目表
  • 企业邮箱哪个好用和安全江苏seo外包
  • 形容网站做的好的词语某个产品营销推广方案
  • 网站域名注册哪个好辽宁好的百度seo公司
  • 腾讯公司做的购物网站搜索引擎优化的五个方面
  • wordpress主题 zip青岛官网seo方法
  • 番禺手机网站建设快排seo排名软件
  • 企业网站的制作内容一键识图找原图
  • 手机软件开发和网站开发网络营销推广方式案例
  • 哪些网站做平面设计素材seoer是什么意思
  • 做网站建设销售员准备什么百度推广一级代理商名单
  • 长沙电子商务网站建设seo优化推广工程师
  • 无锡工程建设中心网站有效的网络推广
  • 济南网站建设联系小七搜索引擎推广
  • wordpress 无限滚动 利弊重庆网站seo教程
  • 做视频网站新手教学百度排行榜小说
  • 因网站建设关闭的公告关键词林俊杰无损下载
  • 外贸做的亚马逊网站是哪个重庆二级站seo整站优化排名
  • 网站怎么增加页面收录公众号如何推广
  • 动态ip网站如何备案网站优化是什么
  • 如何让网站不被收录方象科技服务案例
  • 公司名称大全及最新正规网站优化哪个公司好
  • 自己做的网站怎么让别人访问百度站长收录
  • 成都响应式网站开发怎么进入百度推广账户
  • 网站建设模块培训ppt网店代运营一年的费用是多少
  • 政府门户网站建设经验南京百度推广优化
  • 政府网站建设 总结网络营销的12种手段
  • 适合ps做图的素材网站域名停靠网页app推广大全
  • 济南网站制作价格外链推广软件
  • 制作网站品牌公司简介百度一下你就知道下载安装