Why is logfunc “not defined”?
var logfunc = function(obj) {
return function() {
console.log(obj)
}
}
t += '<a onclick="logfunc(this)"><</a>'
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Reference to
longfuncwould not be accessible if it is declared outside of global scope, fiddleI’m not advocating declaring variables directly in the global scope by omitting
varbut it makes a good example:I would much rather see the function declared separately like
If the option is available to you, I’d suggest using a library like jQuery which offers more flexibility in assigning and handling click events.