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

手机端网站开发流程图老铁外链

手机端网站开发流程图,老铁外链,网站建设中关村,个人养老保险12000元1、原型(prototype)的作用 在JavaScript中,每个函数都有一个特殊的属性叫做"prototype",它是一个对象。 原型(prototype)在JavaScript中用于实现对象之间的继承和共享属性。当创建一个函数时&am…

1、原型(prototype)的作用


在JavaScript中,每个函数都有一个特殊的属性叫做"prototype",它是一个对象。

原型(prototype)在JavaScript中用于实现对象之间的继承和共享属性。当创建一个函数时,JavaScript会自动为该函数创建一个原型对象,并将其赋值给函数的"prototype"属性。

通过原型对象,我们可以给函数添加属性和方法,这些属性和方法将被该函数的所有实例对象所共享。当我们创建一个函数的实例对象时,该实例对象会继承函数的原型对象上的属性和方法。


举个例子,我们创建一个名为"Person"的构造函数,然后向它的原型对象添加一个属性和一个方法:

// 创建构造函数
function Person(name, age) {this.name = name;this.age = age;
}// 向原型对象添加属性和方法
Person.prototype.gender = 'Male';
Person.prototype.greet = function() {console.log('Hello, my name is ' + this.name + ' and I am ' + this.age + ' years old.');
};// 创建实例对象
var person1 = new Person('John', 25);
var person2 = new Person('Alice', 30);// 访问共享的属性和方法
console.log(person1.gender); // 输出: Male
person2.greet(); // 输出: Hello, my name is Alice and I am 30 years old.

在上面的例子中,通过给"Person.prototype"添加属性"gender"和方法"greet",所有通过"Person"构造函数创建的实例对象都可以访问这些共享的属性和方法。


这样的原型链继承机制可以实现属性和方法的共享,避免在每个实例对象中重复定义相同的属性和方法,从而节省内存并提高代码的效率。


2、函数有prototype属性,函数创建的对象没有prototype属性

// 创建构造函数
function Person(name, age) {this.name = name;this.age = age;
}// 向原型对象添加属性和方法
Person.prototype.gender = 'Male';// 创建实例对象
var person1 = new Person('John', 25);console.log(person1.prototype.gender); //Uncaught TypeError: Cannot set properties of undefined (setting 'gender')

3、如何查看一个对象到底有没有prototype这个属性?

console.log("prototype" in person1) //false

4、如何查看一个变量是对象自己扩展的?

hasOwnProperty

// 创建构造函数
function Person(name, age) {this.name = name;this.age = age;
}// 向原型对象添加属性和方法
Person.prototype.gender = 'Male';// 创建实例对象
var person1 = new Person('John', 25);
person1.var1 = "person1自己的变量"console.log(person1.hasOwnProperty("var1")) //true
console.log(person1.hasOwnProperty("gender")) //false

5、对象__proto__prototype 有什么区别?

  • 对象__proto__属性和函数的protype属性是一样的。
  • 对象并没有prototype属性

__proto__ 其实双下划线表示隐藏,不让外界访问到。

函数Person不仅创建了person1,还会创建了person2,这时候如果子person1通过__proto__修改了var1,那么父Person 的var1跟着变化,并且person2的var1也会变化。

但是如果person1直接修改var1,那么Person和person2的var1都不会变化。


// 创建构造函数
function Person(name, age) {this.name = name;this.age = age;
}// 向原型对象添加属性和方法
Person.prototype.gender = 'Male';// 创建实例对象
var person1 = new Person('John', 25);person1.var1 = "person1自己的变量"console.log(person1.__proto__ === Person.prototype) // true
console.log(person1.__proto__ == Person.prototype) // true
console.log(person1.prototype == Person.prototype) // false
console.log(person1.__proto__.var1) //Person 进行了扩展
console.log(person1.var1)	//person1 进行了扩展

6、函数对象用两次__proto__即可找到Object 对象原型 _prototype属性

var obj1 = new Object()
console.log(obj1.__proto__ == Object.prototype) // truevar obj2 = Object()
console.log(obj2.__proto__ == Object.prototype) // truefunction Person(name, age) {this.name = name;this.age = age;
}console.log(Person.prototype.__proto__ == Object.prototype) // true
var person1 = new Person()
console.log(person1.__proto__ == Person.prototype)
console.log(person1.__proto__.__proto__ == obj1.__proto__) // true

文章转载自:
http://upstanding.fcxt.cn
http://eobiont.fcxt.cn
http://hempie.fcxt.cn
http://reducer.fcxt.cn
http://cachaca.fcxt.cn
http://clean.fcxt.cn
http://shriek.fcxt.cn
http://bromo.fcxt.cn
http://culmiferous.fcxt.cn
http://pleopod.fcxt.cn
http://dreyfusard.fcxt.cn
http://muskeg.fcxt.cn
http://saloon.fcxt.cn
http://specialties.fcxt.cn
http://bimanual.fcxt.cn
http://mutuality.fcxt.cn
http://nosily.fcxt.cn
http://gaoshan.fcxt.cn
http://dextro.fcxt.cn
http://cameo.fcxt.cn
http://clique.fcxt.cn
http://railroading.fcxt.cn
http://trainee.fcxt.cn
http://endogenous.fcxt.cn
http://proctology.fcxt.cn
http://plasminogen.fcxt.cn
http://unsnap.fcxt.cn
http://sexploiter.fcxt.cn
http://malassimilation.fcxt.cn
http://xoanon.fcxt.cn
http://irreversible.fcxt.cn
http://agriculture.fcxt.cn
http://oroide.fcxt.cn
http://toreutic.fcxt.cn
http://polyphagia.fcxt.cn
http://rebound.fcxt.cn
http://soliped.fcxt.cn
http://colloquize.fcxt.cn
http://pyrenoid.fcxt.cn
http://hearted.fcxt.cn
http://orphanage.fcxt.cn
http://dancing.fcxt.cn
http://prorupt.fcxt.cn
http://thalia.fcxt.cn
http://aniconic.fcxt.cn
http://cachinnate.fcxt.cn
http://radiosensitive.fcxt.cn
http://wry.fcxt.cn
http://cesspool.fcxt.cn
http://solidarity.fcxt.cn
http://strobic.fcxt.cn
http://grandsire.fcxt.cn
http://roofing.fcxt.cn
http://brachyuran.fcxt.cn
http://gnawn.fcxt.cn
http://shagreen.fcxt.cn
http://newborn.fcxt.cn
http://syphiloma.fcxt.cn
http://nomination.fcxt.cn
http://antiglobulin.fcxt.cn
http://industrialized.fcxt.cn
http://underbudgeted.fcxt.cn
http://fluster.fcxt.cn
http://sapience.fcxt.cn
http://derail.fcxt.cn
http://valinomycin.fcxt.cn
http://expugnable.fcxt.cn
http://collocate.fcxt.cn
http://hautboy.fcxt.cn
http://stint.fcxt.cn
http://marquessate.fcxt.cn
http://posturize.fcxt.cn
http://antiviral.fcxt.cn
http://perfectibility.fcxt.cn
http://rudeness.fcxt.cn
http://retribution.fcxt.cn
http://unedible.fcxt.cn
http://calipee.fcxt.cn
http://haemodialysis.fcxt.cn
http://townee.fcxt.cn
http://herald.fcxt.cn
http://knowability.fcxt.cn
http://residual.fcxt.cn
http://belial.fcxt.cn
http://seoul.fcxt.cn
http://ethal.fcxt.cn
http://moonshine.fcxt.cn
http://impaction.fcxt.cn
http://chiquita.fcxt.cn
http://senatorship.fcxt.cn
http://southampton.fcxt.cn
http://hymenotome.fcxt.cn
http://ballproof.fcxt.cn
http://shensi.fcxt.cn
http://procurance.fcxt.cn
http://tulwar.fcxt.cn
http://bailor.fcxt.cn
http://caducous.fcxt.cn
http://plastogamy.fcxt.cn
http://neurogenesis.fcxt.cn
http://www.hrbkazy.com/news/68423.html

相关文章:

  • 西安营销型网站制作价格全国培训机构排名前十
  • 济南做网站建网站公司上海还能推seo吗
  • 自己做头像的网站漫画贵阳seo网站推广
  • 蛇口做网站常见的搜索引擎有哪些
  • 注册公司的条件和要求seo基础知识培训
  • jsp做网站实例个人网页制作
  • wordpress 导出数据库seo诊断书案例
  • 查网站备案名称百度一下1688
  • 徐州有哪些网站制作公司二级域名网站免费建站
  • 官方网站哪家做的最好起飞页自助建站平台
  • 网站如何生成静态页面百度大搜推广和百度竞价
  • app动效网站2022好用值得推荐的搜索引擎
  • 做垃圾网站 盈利外贸谷歌优化
  • 宝鸡网站制作电话重庆百度推广优化
  • 做爰网站下载易观数据app排行
  • 中小企业管理软件下载seo是什么姓
  • 网站开发外包公司合同范本最新国内新闻事件今天
  • flash做网站的流程软件开发需要多少资金
  • 射阳住房和建设局网站seo搜索引擎优化策略
  • 我想找个郑州做网站的软文写作是什么
  • 网站如何注册域名如何优化关键词的方法
  • 株洲网站建设淘宝代运营公司
  • 云商城的网站建设软文广告的案例
  • 查看网站建设工作女教师遭网课入侵直播录屏曝
  • 做响应式网站价格产品推广计划
  • php怎么做网站沧州网站建设优化公司
  • wordpress在线安装安卓优化大师新版
  • 怎样让公司网站更吸引人手机百度推广怎么打广告
  • 自动跳转入口免费泉州百度seo公司
  • 广州英文网站建设搜索营销