Java code
//The first way to write
function Circle(r) {
= r;
}
= 3.14159;
= function() {
return * * ;
}
var c = new Circle(1.0);
alert(());
Java code
//The second way of writing
var Circle = function() {
var obj = new Object();
= 3.14159;
= function( r ) {
return * r * r;
}
return obj;
}
var c = new Circle();
alert( ( 1.0 ) );
Java code
//The third way of writing
var Circle = new Object();
= 3.14159;
= function( r ) {
return * r * r;
}
alert( ( 1.0 ) );
Java code
//The fourth way of writing
var Circle={
"PI":3.14159,
"area":function(r){
return * r * r;
}
};
alert( (1.0) );
Java code
//The fifth way to write
var Circle = new Function(" = 3.14159; = function( r ) {return r*r*;}");
alert( (new Circle()).area(1.0) );
Let’s discuss these five writing methods, which one is more standardized, especially the last two, which are often seen.
Copy the codeThe code is as follows:
//The first way to write
function Circle(r) {
= r;
}
= 3.14159;
= function() {
return * * ;
}
var c = new Circle(1.0);
alert(());
Java code
Copy the codeThe code is as follows:
//The second way of writing
var Circle = function() {
var obj = new Object();
= 3.14159;
= function( r ) {
return * r * r;
}
return obj;
}
var c = new Circle();
alert( ( 1.0 ) );
Java code
Copy the codeThe code is as follows:
//The third way of writing
var Circle = new Object();
= 3.14159;
= function( r ) {
return * r * r;
}
alert( ( 1.0 ) );
Java code
Copy the codeThe code is as follows:
//The fourth way of writing
var Circle={
"PI":3.14159,
"area":function(r){
return * r * r;
}
};
alert( (1.0) );
Java code
Copy the codeThe code is as follows:
//The fifth way to write
var Circle = new Function(" = 3.14159; = function( r ) {return r*r*;}");
alert( (new Circle()).area(1.0) );
Let’s discuss these five writing methods, which one is more standardized, especially the last two, which are often seen.