Get the App
SLTechnology News&Howtos  ›  Development  › 

How to calculate the area of the drawing by javascript

Shulou Source: shulou.com Published: 2022-06-02 23:25:49 11月08日 Update

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:

Tags: Area graphics function learning content ordinary that is form idea situation article method time more environment computer knowledge knowledge point rectangle article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn macOS Huawei Shulou Tech Info MariaDB