OOP mit JavaScript
(Unterschied zwischen Versionen)
(Die Seite wurde neu angelegt: „= OOP mit JavaScript = == Einleitung == Dieses Tutorial basiert auf einen [http://phrogz.net/js/classes/OOPinJS.html Artikel] von Gavin Kistner und dessen [http:…“) |
(→Deklaration von Klassen) |
||
| Zeile 5: | Zeile 5: | ||
== Deklaration von Klassen == | == Deklaration von Klassen == | ||
| + | {| | ||
| + | ! PHP | ||
| + | ! C++ | ||
| + | ! JavaScript | ||
| + | |- | ||
| + | |<pre> | ||
| + | class Point2D | ||
| + | { | ||
| + | public $x; | ||
| + | public $y; | ||
| + | |||
| + | function __construct( $x = 0, $y = 0 ) | ||
| + | { | ||
| + | $this->x = $x; | ||
| + | $this->y = $y; | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
| + | |<pre> | ||
| + | class Point2D | ||
| + | { | ||
| + | public: | ||
| + | double x; | ||
| + | double y; | ||
| + | |||
| + | Point2D( double _x = 0, double _y = 0 ) | ||
| + | { | ||
| + | x = _x; | ||
| + | y = _y; | ||
| + | } | ||
| + | }; | ||
| + | </pre> | ||
| + | |<pre> | ||
| + | function Point2D( x, y ) | ||
| + | { | ||
| + | this.x = x ? x : 0; | ||
| + | this.y = y ? y : 0; | ||
| + | } | ||
| + | </pre> | ||
| + | |} | ||
Version vom 12:24, 7. Sep. 2010
OOP mit JavaScript
Einleitung
Dieses Tutorial basiert auf einen Artikel von Gavin Kistner und dessen Korrektur durch Shelby H. Moore III.
Deklaration von Klassen
| PHP | C++ | JavaScript |
|---|---|---|
class Point2D
{
public $x;
public $y;
function __construct( $x = 0, $y = 0 )
{
$this->x = $x;
$this->y = $y;
}
}
|
class Point2D
{
public:
double x;
double y;
Point2D( double _x = 0, double _y = 0 )
{
x = _x;
y = _y;
}
};
|
function Point2D( x, y )
{
this.x = x ? x : 0;
this.y = y ? y : 0;
}
|