1
0
Fork 0

Syntax highlighting for README.md

closure/master
Mike Gerwitz 2011-05-23 07:01:58 -04:00
parent af411edf43
commit d1fbf4cc21
1 changed files with 14 additions and 0 deletions

View File

@ -39,6 +39,7 @@ examples below, [Node.js](http://nodejs.org) is used.
The constructor is provided as the `__construct()` method (influenced by The constructor is provided as the `__construct()` method (influenced by
[PHP](http://php.net)). [PHP](http://php.net)).
````javascript
var Class = require( 'easejs' ).Class; var Class = require( 'easejs' ).Class;
// anonymous class definition // anonymous class definition
@ -61,15 +62,18 @@ The constructor is provided as the `__construct()` method (influenced by
return this._name; return this._name;
} }
}); });
````
The above creates an anonymous class and stores it in the variable ``Dog``. You The above creates an anonymous class and stores it in the variable ``Dog``. You
have the option of naming class in order to provide more useful error messages have the option of naming class in order to provide more useful error messages
and toString() output: and toString() output:
````javascript
var Dog = Class( 'Dog', var Dog = Class( 'Dog',
{ {
// ... // ...
}); });
````
### Extending Classes ### Extending Classes
Classes may inherit from one-another. If the supertype was created using Classes may inherit from one-another. If the supertype was created using
@ -86,6 +90,7 @@ interfaces and traits.
**Note that interfaces, traits and mixins are not yet available. They are **Note that interfaces, traits and mixins are not yet available. They are
planned features and should be available shortly.** planned features and should be available shortly.**
````javascript
var SubFoo = Foo.extend( var SubFoo = Foo.extend(
{ {
'public anotherMethod': function() 'public anotherMethod': function()
@ -101,12 +106,14 @@ planned features and should be available shortly.**
{ {
}, },
}); });
````
### Abstract Classes ### Abstract Classes
Abstract classes require that their subtypes implement certain methods. They Abstract classes require that their subtypes implement certain methods. They
cannot be instantiated. Classes are automatically considered to be abstract if cannot be instantiated. Classes are automatically considered to be abstract if
they contain one or more abstract methods. they contain one or more abstract methods.
````javascript
var Class = require( 'easejs' ).Class; var Class = require( 'easejs' ).Class;
var AbstractFoo = Class( var AbstractFoo = Class(
@ -118,6 +125,7 @@ they contain one or more abstract methods.
// alternatively, you needn't supply implementation details // alternatively, you needn't supply implementation details
'abstract public fooBar2': [], 'abstract public fooBar2': [],
}); });
````
If the abstract method provides implementation details (as shown by If the abstract method provides implementation details (as shown by
`fooBar()`, subtypes must implement at least that many arguments or an exception `fooBar()`, subtypes must implement at least that many arguments or an exception
@ -128,6 +136,7 @@ subtype to be instantiated, it must provide concrete implementations of each
abstract method. If any methods are left as abstract, then the subtype too will abstract method. If any methods are left as abstract, then the subtype too will
be considered abstract. be considered abstract.
````javascript
// can be instantiated because concrete methods are supplied for both // can be instantiated because concrete methods are supplied for both
// abstract methods // abstract methods
var ConcreteFoo = AbstractFoo.extend( var ConcreteFoo = AbstractFoo.extend(
@ -148,6 +157,7 @@ be considered abstract.
{ {
}, },
}); });
````
You may determine if a class is abstract by calling its `isAbstract()` method. You may determine if a class is abstract by calling its `isAbstract()` method.
The abstract methods are available as a read-only `abstractMethods` property. The abstract methods are available as a read-only `abstractMethods` property.
@ -163,17 +173,21 @@ The abstract methods are available as a read-only `abstractMethods` property.
Interfaces can be declared in a very similar manner to classes. All members of Interfaces can be declared in a very similar manner to classes. All members of
an interface must be declared as abstract. an interface must be declared as abstract.
````javascript
var MyType = Interface( var MyType = Interface(
{ {
'abstract public foo': [] 'abstract public foo': []
}); });
````
To implement an interface, use the `implement()` class method: To implement an interface, use the `implement()` class method:
````javascript
var ConcreteType = Class.implement( MyType ).extend( var ConcreteType = Class.implement( MyType ).extend(
{ {
'public foo': function() {} 'public foo': function() {}
}); });
````
## Use of Reserved Words ## Use of Reserved Words