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

How to calculate the area of the drawing by javascript

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "javascript how to find the area of graphics", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "javascript how to find the area of graphics"!

Javascript method for calculating the area of a graph: [function Circle (r) {if (this instanceof Circle) {this.r=r; this.area=function () {return Math.PI*this].

This article operating environment: windows10 system, javascript 1.8.5, thinkpad T480 computer.

Figure area solution:

The first kind: constructor

Document function Retangle (this instanceof Retangle b) {if (this instanceof Retangle) {this.a=a; this.b=b; this.area=function () {return this.a*this.b; / / console.log (Math.PI*this.r*this.r) } this.premeter=function () {return (this.a+this.b) * 2; / / console.log (Math.PI*this.r*2);}} else {return new Retangle (amemb);}} let c=new Retangle (10mem10) / / console.log (c instanceof Circle); / / judge Bool value console.log (c.area ()); console.log (c.premeter ()); Retangle (10Ling 10)

Area of the circle:

Document function Circle (r) {if (this instanceof Circle) {this.r=r; this.area=function () {return Math.PI*this.r*this.r;} this.premeter=function () {return Math.PI*this.r*2 }} else {return new Circle (r);}} let c=new Circle (10); / / console.log (c instanceof Circle); console.log (c.area ()); console.log (c.premeter ()); Circle (10)

There are two forms of output:

Windows- ordinary function

Circle (10); console.log (window.r); console.log (window.area ()); console.log (window.premter ())

Constructor function

Let c = new Circle (10); / / console.log (c); console.log (c instanceof Circle); console.log (c.r); console.log (c.area ()); console.log (c.premter ())

The second kind:

Title function Retangle () {var a = document.getElementById ("A1"). Value; var b = document.getElementById ("b1"). Value; alert ("rectangular area:" + aqb);} length:

Width:

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