-
Notifications
You must be signed in to change notification settings - Fork 0
4. Creating And Extending a Class
fahimc edited this page Apr 15, 2013
·
8 revisions
Creating a Class and Extending Video
Overriding and Calling Super Video
Creating an Interface
var View = function() {
}
This is how you define a class.
var View = function() {
}
Class.extend(View, UIElement);
Now the View class will inherit the UIElement.
var view = new View();
Class._super(this, "name of super function",argument1,argument2, etc..);
To override a function all you do is create a new class and within it you create that function. Use 'this' to reference the current class.
var View = function() {
this.build = function() {
Class._super(this, "build");
}
}
Class.extend(View, UIElement);
Once you've created a class and extended it you can create inheritable methods by adding methods to its prototype.
var View = function() {
this.build = function() {
Class._super(this, "build");
}
}
Class.extend(View, UIElement);
var _ = View.prototype;
_.viewName = "test view";
_.getName = function()
{
return this.viewName;
}
Create a literal object as an Interface and call the implement method with two parameters, the new Class/object and the Interface object.
var IView =
{
//now lets put some methods into it
build:function(){
},
setColor:function(color)
{
},
visible:false
};
// create a class and you can override methods
var View = function(){
this.setColor=function(color)
{
return color;
}
};
// call the implement method
Class.implement(View,IView);