2

I am defining a javascript prototype with a function that has a jquery selector in it. An over simplified version of my code can be found below:

function MyObj(id1){
this.id1 = id1;
}
MyObj.prototype.MyFunc = function(id2){
$('#' + this.id1).val(id2)
}
var newObj = new MyObj("id1_val");

I cannot use this in MyFunc, because this is the context (as perseved by JQuery), Is there a way to access the value of id1? Is it even possible to have a prototype with a function that has jquery in it?

I do need to maintain access to the context, because the code is part of a form submission and I have $(this).submit();


EDIT: I have a function

bar(id2){
 var newObj = new MyObj("id1_val");
 Foo(id2, newObj.MyFunc)
}

bar is being called in fuction start() {bar}; window.onload = start;

Quantico
  • 2,398
  • 7
  • 35
  • 59

0 Answers0