Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

JavaScript defines instances of prototype objects and inherited objects

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "JavaScript definition prototype object and inheritance object example", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "JavaScript definition prototype object and inheritance object instance"!

Define prototype objects and inherit objects. The sample code is as follows:

Prototype _ object _ inheritance

{

Function Circle (xmemy r)

{

This.x=x

This.y=y

This.r=r

}

Circle.prototype.pi = 3.1415926

Function Circle_circumference ()

{

Return 2*this.pi*this.r

}

Circle.prototype.circumference = Circle_circumference

Var c = new Circle (0.0,0.0,5)

Var p = c.circumference ()

[xss_clean] ("the perimeter of circle c is Circle (0.0,0.0,5):", p)

[xss_clean] ("inheritance")

Function Circle_area ()

{

Return this.pi*this.r*this.r

}

Circle.prototype.area = Circle_area

Var mji = c.area ()

[xss_clean] ("the area of circle c is:", mji)

[xss_clean] ("redefinition: do not inherit Circle (0.0,0.0,10);")

Var C3 = new Circle (0.0,0.0,10)

Function area ()

{

Return 3*this.pi*this.r*this.r

}

C3.area = area

P = C3.circumference ()

Mji = C3.area ()

[xss_clean] ("the circumference of the C3 circle is:", p)

[xss_clean] ("the area of C3 circle is:", mji)

}

Thank you for reading, the above is the content of "JavaScript defines instances of prototype objects and inherited objects". After the study of this article, I believe you have a deeper understanding of the problem of defining instances of prototype objects and inherited objects by JavaScript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report