rendered paste body<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function my_class(name)
{
this.name = name;
this.bind_events = bind_events;
this.method = function() { alert("the method called from, "+ this.name); }
}
function bind_events()
{
var divs = document.getElementsByTagName("div");
var i, len = divs.length;
for (i = 0; i < len; i++)
{
divs[i].obj = this;
divs[i].onclick = click_div;
}
}
function click_div()
{
this.obj.method();
}
window.onload = function()
{
var obj = new my_class("object 1");
obj.bind_events();
obj = new my_class("object 2");
obj.bind_events();
}
</script>
<style>
div
{
margin:50px;
width:150px;
height:50px;
background-color:#000000;
cursor:pointer;
}
</style>
</head>
<body>
<div id="one"> </div>
<div id="two"> </div>
<div id="three"> </div>
<div id="four"> </div>
</body>
</html>