Sunday, July 1, 2018

Creating Classes in JS

Example of creating a class in js, having both properties and functions/methods

<html>
<head>
 <meta charset="UTF-8">
<script>

/* Definig a JS Class with PROPERTIES and METHODS */
/* Use Inspect Element-->Console , to see errors and debug your js code */
var apple = {
    type: "macintosh",
    color: "red",
    getInfo: function () {
        return this.color + ' ' + this.type + ' apple';
    },
    arr:["22","11","33","44"]
}


function f1(){

apple.color="Green";
alert(apple.getInfo());
alert("length = " +apple.arr.length+" Actual array = "+apple.arr +" Revesre Array is = " +apple.arr.reverse());
alert("Now array is = "+apple.arr+" Slice array is = "+ apple.arr.slice(1)+" Sorted array "+ apple.arr.sort());
alert("History length = "+ history.length + " Page location = "+ window.location+ " Protocol = "+ window.location.href);
//window.location.reload();
window.location.replace("///D:/Aa_MCA_I/MCSL016%20Internet%20and%20Web%20design/forms0.html");

}


</script>
</head>

<body onLoad="f1()" >
<h1> Creating a 'Class' in Js </h1>
</body>
</html>


No comments:

Post a Comment

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows