Вы можете передать эту переменную в обратный вызов:
function clslevel(id){
var the_id = id;
this.methodOne=function(param){
param(the_id);
return this;
};
this.methodTwo=function(param){
param();
return this;
};
}
function level(id){
return new clslevel(id);
}
level("myButton")
.methodOne(
function(passed_id){
console.log("methodOne called.");
console.log(passed_id)
// how can I access the variable 'the_id' in clslevel() from here?
}
)
.methodTwo(
function(){
console.log("methodTwo called");
}
)