2
class TaskRepo(taskData: TaskData) {

companion object {
    private val repoByTask: LRUMap<String, OrderFormRepo> = LRUMap(2, 10);

     fun getInstance(taskData: TaskData): OrderFormRepo {
        if (notFoundObject(taskData.taskId)) {
            repoByTask[taskData.taskId] = OrderFormRepo(taskData);
        }
        return repoByTask[taskData.taskId];//PROBLEM HERE
    }

    private fun notFoundObject(taskId: String): Boolean {
        if (repoByTask.containsKey(taskId) && repoByTask[taskId] != null) {
            return false
        }
        return true
    }
}

}

in getInstance method of companion object I am getting compile time error: Required TaskRepo and found TaskRepo?


How to pass a parameter and an event into a function

I have had a (simple) problem I can't solve for a while. I don't know how to combine myFunction1 and myFunction2 into one function.

<a href="https://www.google.com" id="link1">link1</a>
<a href="https://www.google.com" id="link2">link2</a>
<a href="https://www.google.com" id="link3">link3</a>

function myFunction1(val){
  console.log(val);
}
function myFunction2(e){
  console.warn('preventDefault');
  e.preventDefault();
}
/* this one doesn't work */
function myFunction3(val, e){
  console.log(val);
  console.warn('preventDefault');
  e.preventDefault();
}

document.getElementById('link1').onclick = function(e){
  myFunction1('hello');
};
document.getElementById('link2').onclick = function(e){
  myFunction2(e);
};
document.getElementById('link3').onclick = function(e){
  myFunction3(e, val);
};

So my question is simple, how do you get the third one to work. Work being: passing the val parameter and making the preventDefault work. So how do you combine myFunction1 and myFunction2 into one function?

4

1 に答える 1