An object initializer creates an object via an initialization list. The program below creates two objects via initializers. The second object is a line object that is created via multiple nested initializers.
<!DOCTYPE html> <html> <head> <title>XoaX.net's Javascript</title> </head> <body> <script type="text/javascript" src="ObjectInitializers.js"></script> </body> </html>
var qPoint2D = { dX:3.5, dY:8.2}; document.write("X = " + qPoint2D.dX + "<br />"); document.write("Y = " + qPoint2D.dY + "<br />"); document.write("<br />"); var qLine = { mqP1:{dX:1.03, dY:5.6}, mqP2:{dX:3.9, dY:7.81}}; document.write("P1 = (" + qLine.mqP1.dX + ", " + qLine.mqP1.dY + ")<br />"); document.write("P2 = (" + qLine.mqP2.dX + ", " + qLine.mqP2.dY + ")<br />");
© 20072024 XoaX.net LLC. All rights reserved.