The function is not working, It is not putting values in "input".
function example(id){
this.code= function(){$('.'+id).val(id)}
this.validate= function (){
$('.'+id).keyup(function (e){
if(e.keyCode==13) this.code();
})
}
}
body
<input type="text" class="test"/>
<input type="text" class="test1"/>
<script type="text/javascript">
var test= new example('test')
var test1= new example('test1')
test.validate()
test1.validate()
</script>
this.codewill inherit the parent function's scope, and will have knowledge of theidvar.validate()function just registeres akeyuphandler, and does not actually perform the validation?