SoFunction
Updated on 2025-04-06

javascript Base class contains basic methods


<script type="text/javascript">
function Base(){} //root abstract class
=function(){ // Method to convert an object into an instance of the Base class
return new Base();
}
=function(parent){ //Methods used to inherit instances of Base class
var F=function(){}
=parent;
return new F;
}
= function(prop){ //Extend method of extending the root abstract class Base
for (var o in prop) {
this[o] = prop[o];
}
}
= function(name, fn){ //Extend the method method of the root abstract class Base
this[name] = fn;
return this;
}
var o=new Base(); //Create a Base instance
("show",function(){ //Add a show method to object o
alert("show function");
});
({ //Add name attribute and say function to object o
name:"shupersha",
say:function(){
alert("say function")
}
});
var t=(o); //Inherit the properties and methods of the o object
();
();
</script>