Step: 2 Codes
var doc = false; var x1=""; var x2="";
//function is an object in JavaScript, function with () is a
constructor
// ( it is not comparable with with C# or Java
function myPetConstructor(b1, b2) {
doc.innerHTML += "<br/> Consturctor Fired";
this.x1 = b1; this.x2 = b2;
this.x1Return = function(x1) { if (this.x1 == b1) { return ("nice "
+ x1); } };
this.x2Return = function(x2) { if (this.x2 == b2) { return ("price "
+ x2); } };
}
// var pet1 = new myPetConstructor(this.x1,this.x2);
function start(a1, a2) {
doc.innerHTML += x1 + x2;
//propIn JavaScript when an object is created fom an existing object
//is a prototype of the reference object
//below pet2 is a prototype of object myPetConstructor
var pet2 = new myPetConstructor(a1, a2);
doc.innerHTML += "<br/> check prototype ! " +
myPetConstructor.prototype.isPrototypeOf(pet2);
doc.innerHTML += "<br/>pet2.constructor " + (pet2.constructor ==
myPetConstructor.prototype.constructor);
doc.innerHTML += "<br/>"+ pet2.x1 + " -match-" + pet2.x1Return(a1);
doc.innerHTML += "<br/>" + pet2.x2 + " -match-" + pet2.x2Return(a2);
}
window.onload = function() {
//start("java", "prog");
doc = document.getElementById("output");
}
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>mm.OOJavaScript7</title>
</head>
<body>
<form id="form1" runat="server">
<a href="#" onclick="start('Kitty','$300')"> Click Me</a>
<div id="output"></div>
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/myObjects.js" />
</Scripts>
</asp:ScriptManager>
</div>
</form>
</body>
</html>