HTML and CSS Reference
In-Depth Information
Table 8.2 Some Object Methods (continued)
Method
What It Does
hasOwnProperty(property)
Returns true if the specified property belongs to this object, not
inherited from its prototype object chain.
isPrototypeOf(object)
Returns true if this object is one of the parent prototype objects
of the specified child object.
You can also use the instanceof operator to test if the specified object is of the specified
object type. If it is, true is returned.
FORMAT
var isInstance = objectName instanceof objectType;
EXAMPLE
var str1 = new String("good morning");// Create a new string object
var result = sr1 instanceof String ;
if( result == true ){ }
EXAMPLE 8.15
<html>
<head><title>Object object</title>
<script type="text/javascript">
1
function Book(title, author){
this.title =title;
this.author=author;
}
</script>
</head>
<body bgColor="#EOFFFF">
<big>
<script>
2
Book.prototype.publisher="Oxford Press";
3
Object.prototype.category="Fiction";
4
var tale = new Book("Kidnapped","R.L.Stevenson");
5
document.write("The value of Object's category property is "+
Object.prototype.category +"<br />");
6
if( tale.constructor == Book ){
document.write("tale is a Book object<br />");
document.write("The Book's constructor is defined as: "+
7
tale.constructor + "<br />");
}
Continues
 
Search WWH ::




Custom Search