1. Define type
function UserObject (parameter) {
}
parameter can be omitted, which is equivalent to the constructor parameter in C#.
2. Instantiate the custom type
3. Add attributes
function userobject(parameter){
this.firstproperty=parameter
this.secondproperty=" This is the second property"
}
//Use
<script> <br>var myobject=new userobject("hi there.") <br>//alerts "hi there." <br>alert(myobject.firstproperty) <br>//writes "This is the second property" <br>document.write(myobject.secondproperty) <br></script>
4. Add method (circle class )
//first method function
function computearea(){
var area=this.radius*this.radius*3.14
return area
}
//second method function
function computediameter(){
var diameter =this.radius*2
return diameter
}
Associated to the custom type:
Use custom method:
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn