Hello guys! how you all doing today? Welcome to my new tutorial post on JavaScript. In the last tutorial, we talked about the ultimate guide to JavaScript Date object and i used a table to list out the Date properties available in JavaScript.
So like i made mention in my last tutorial post, i will be using some examples to illustrate how these Date properties can be implemented. We have only two Date properties available in JavaScript and i will start this tutorial with the Date constructor property.
So like i made mention in my last tutorial post, i will be using some examples to illustrate how these Date properties can be implemented. We have only two Date properties available in JavaScript and i will start this tutorial with the Date constructor property.
You can also read our tutorial post on: How to implement JavaScript String Properties with clear examples
Date constructor Property
JavaScript date constructor property returns a reference to the array function that created the instance's prototype.
Syntax
Its syntax is as follows -
date.constructor
Return Value
Returns the function that created this object's instance.
Example
You can try the following example below.
<html>
<head>
<title>JavaScript Date constructor Property</title>
</head>
<body>
<script type ="text/javascript">
var dt = new Date();
document.write("dt.constructor is : " + dt.constructor );
</script>
</body>
</html>
<head>
<title>JavaScript Date constructor Property</title>
</head>
<body>
<script type ="text/javascript">
var dt = new Date();
document.write("dt.constructor is : " + dt.constructor );
</script>
</body>
</html>
Output
Below is the output of the above example.
dt.constructor is : function Date() { [native code] }
You can also read our tutorial post on: Learn the various ways in which JavaScript can be used to redirect a web page to another
Object Prototype
The prototype property allows you to add properties and methods to any object(Number, Boolean, String and Date etc.).
Note - Prototype is a global property which is available with almost all the objects.
Note - Prototype is a global property which is available with almost all the objects.
Syntax
Its syntax is as follows -
object.prototype.name = value
Example
Try the following example below
<html>
<head>
<title>User-defined objects</title>
<script type = "text/javascript">
function book(title, author) {
this.title = title;
this.author = author;
}
</script>
</head>
<body>
<script type ="text/javascript">
var myBook = new book("Java", "Kennedy");
book.prototype.price = null;
myBook.price = 300;
document.write("Book title is : " + myBook.title + "<br />" );
document.write("Book author is : " + myBook.author + "<br />" );
document.write("Book price is : " + myBook.price + "<br />" );
</script>
</body>
</html>
<head>
<title>User-defined objects</title>
<script type = "text/javascript">
function book(title, author) {
this.title = title;
this.author = author;
}
</script>
</head>
<body>
<script type ="text/javascript">
var myBook = new book("Java", "Kennedy");
book.prototype.price = null;
myBook.price = 300;
document.write("Book title is : " + myBook.title + "<br />" );
document.write("Book author is : " + myBook.author + "<br />" );
document.write("Book price is : " + myBook.price + "<br />" );
</script>
</body>
</html>
Output
Below is the output of the above example.
Book title is : Java
Book author is : Kennedy
Book price is : 300
Book author is : Kennedy
Book price is : 300
You can also read our tutorial post on: JavaScript For Loop
Alright guys! this is where we are going to wrap it up on this tutorial. In my next tutorial we will be discussing about the Date methods in details with series of examples.
Feel free to drop your questions via the comment box below, they will be attended to as soon as possible. Follow us on our various social media platforms available to stay updated with our latest tutorials.
Thanks for reading and bye for now.
Feel free to drop your questions via the comment box below, they will be attended to as soon as possible. Follow us on our various social media platforms available to stay updated with our latest tutorials.
Thanks for reading and bye for now.