Created
April 2, 2011 21:22
-
-
Save gossi/899912 to your computer and use it in GitHub Desktop.
Ideas for defining properties on Javascript "classes"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Method 1: | |
MyClass = Class({ | |
extends : "AnotherClass", | |
mixins : ["Event"], | |
construct : function () { | |
console.log("constructor message"); | |
}, | |
static : { | |
prop : 5 | |
}, | |
private : { | |
}, | |
protected : { | |
}, | |
public : { | |
testFunc : function () { | |
// do something ... | |
} | |
} | |
}); | |
//Method 2: | |
MyClass = Class({ | |
extends : "AnotherClass", | |
mixins : ["Event"], | |
construct : function () { | |
console.log("constructor message"); | |
}, | |
contents : { | |
"prop" : { | |
value : 5, | |
final : "true|false", | |
visibility : "public|protected|private", | |
static : "true|false" | |
}, | |
"testFunc" : { | |
value : function () { | |
// do something... | |
}, | |
final : "true|false", | |
visibility : "public|protected|private", | |
static : "true|false" | |
} | |
} | |
}); | |
//Method 3: | |
MyClass = Class({ | |
extends : "AnotherClass", | |
mixins : ["Event"], | |
construct : function () { | |
console.log("constructor message"); | |
}, | |
static : { | |
prop : 5 | |
}, | |
private : { | |
}, | |
protected : { | |
}, | |
public : { | |
testFunc : function () { | |
// do something ... | |
} | |
}, | |
extended : { | |
"prop" : { | |
value : 5, | |
final : "true|false", | |
visibility : "public|protected|private", | |
static : "true|false" | |
}, | |
"anotherFunc" : { | |
value : function () { | |
// do something... | |
}, | |
final : "true|false", | |
visibility : "public|protected|private", | |
static : "true|false" | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment