JavaScript 面向對象框架:jOOPL
jOOPL 是一個 JavaScript 面向對象框架,全稱是:"JavaScript Object-Oriented Programming Library".
是一個輕量級、易用的面向對象編程庫,允許使用純 JavaScript 實現高級面向對象特性,包括:
- 繼承.
- 多態
- 封裝
- 組合

示例代碼:
// First of all, we are going to declare a namespace for the class
$namespace.register("Joopl.Samples");
// Next part will be about designing the whole class
Joopl.Samples.Polygon = $class.declare(
// The constructor
function() {
// This is very recommended: if you declare a class field in the constructor,
// it will hold a default value instead of undefined
this.$_.args = null;
},
{
// Sets an object that will hold the arguments to calculate the polygon's area
set_Args: function(value) {
this.$_.args = value;
},
// Gets an object that will hold the arguments to calculate the polygon's area
get_Args: function() {
return this.$_.args;
},
// The method to calculate the area. Check that its body does implement nothing.
// Derived classes will be the ones responsible of providing the formula to make the calculation.
CalculateArea: function() {
}
}
);
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!