MooTools是一种可用于设计面向对象模型的工具.让我们在本章中讨论一个MooTools库的简单示例.
这里我们将使用Class设计一个名为Rectangle的模型.为此,我们需要声明属性 - 宽度和高度.
查看以下代码,并将其保存到sample.html中.
<html> <head> <script type = "text/javascript" src = "MooTools-Core-1.6.0.js"></script> <script type = "text/javascript" src = "MooTools-More-1.6.0.js"></script> <script type = "text/javaScript"> var Rectangle = new Class({ //properties width: 0, height: 0, //methods initialize: function(widthVal, heightVal) { this.width = widthVal; this.height = heightVal; }, details: function() { document.write("Welcome to MooTools demo program"); document.write("Width: "+this.width+" Height: "+this.height); }, }); var rec = new Rectangle(5,4); rec.details(); </script> </head> <body> </body> </html>
您将收到以下输出 :