First example that addresses node.js as primary execution environment.
This commit is contained in:
parent
a48438c562
commit
11e2179dd3
3 changed files with 35 additions and 26 deletions
|
|
@ -1,15 +1,16 @@
|
|||
// file: runme.js
|
||||
var example = require("./build/Release/example");
|
||||
|
||||
// ----- Object creation -----
|
||||
|
||||
print("Creating some objects:");
|
||||
console.log("Creating some objects:");
|
||||
c = new example.Circle(10);
|
||||
print("Created circle " + c);
|
||||
console.log("Created circle " + c);
|
||||
s = new example.Square(10);
|
||||
print("Created square " + s);
|
||||
console.log("Created square " + s);
|
||||
|
||||
// ----- Access a static member -----
|
||||
print("\nA total of " + example.Shape.nshapes + " shapes were created"); // access static member as properties of the class object
|
||||
console.log("\nA total of " + example.Shape.nshapes + " shapes were created"); // access static member as properties of the class object
|
||||
|
||||
// ----- Member data access -----
|
||||
// Set the location of the object.
|
||||
|
|
@ -21,26 +22,26 @@ c.y = 30;
|
|||
s.x = -10;
|
||||
s.y = 5;
|
||||
|
||||
print("\nHere is their new position:");
|
||||
print("Circle = (" + c.x + "," + c.y + ")");
|
||||
print("Square = (" + s.x + "," + s.y + ")");
|
||||
console.log("\nHere is their new position:");
|
||||
console.log("Circle = (" + c.x + "," + c.y + ")");
|
||||
console.log("Square = (" + s.x + "," + s.y + ")");
|
||||
|
||||
// ----- Call some methods -----
|
||||
print("\nHere are some properties of the shapes:");
|
||||
print("Circle:");
|
||||
print("area = " + c.area() + "");
|
||||
print("perimeter = " + c.perimeter() + "");
|
||||
print("\n");
|
||||
print("Square:");
|
||||
print("area = " + s.area() + "");
|
||||
print("perimeter = " + s.perimeter() + "");
|
||||
console.log("\nHere are some properties of the shapes:");
|
||||
console.log("Circle:");
|
||||
console.log("area = " + c.area() + "");
|
||||
console.log("perimeter = " + c.perimeter() + "");
|
||||
console.log("\n");
|
||||
console.log("Square:");
|
||||
console.log("area = " + s.area() + "");
|
||||
console.log("perimeter = " + s.perimeter() + "");
|
||||
|
||||
// ----- Delete everything -----
|
||||
print("\nGuess I'll clean up now");
|
||||
console.log("\nGuess I'll clean up now");
|
||||
// Note: this invokes the virtual destructor
|
||||
delete c;
|
||||
delete s;
|
||||
delete s;
|
||||
|
||||
print (example.Shape.nshapes + " shapes remain");
|
||||
console.log(example.Shape.nshapes + " shapes remain");
|
||||
|
||||
print("Goodbye");
|
||||
console.log("Goodbye");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue