It's best not to make assumptions about what's obvious. It wasn't a problem here, but too often have I seen someone asking for help make an assumption about a key point. Break that habit while you can. Always be explicit about where an error occurs, and what the error is, even if they seem obvious. If nothing else, this shows you're actively working on the problem and not simply trying to pass it on to someone else.I thought that was too obvious to require explicit statement as there were only three js files on my page and two of them were the jquery and its ui repectively, and no one here expect that I wrote both of them too, right?
Not that every bit of information about the problem needs to be included. Extraneous information should be filtered out. The filtering impulse is a good one, it's just a matter of tuning your filters.
I didn't read it as rude, even though I was myself certainly being gruff. The link to the "Laziness, Impatience and Hubris" page was intended to cut my gruffness somewhat.I'm not being rude here, I know that I have no right to be-maybe I'm just a lazy little boy,bad lazy-in your words. Anyway, guys like you here help me a lot, and 'm thankful to that; so I'll follow your advice and make the info as explicit as possible in future.
If that line is run from within slider.build, then this should refer to a slider. If it isn't working as you'd expect, I'd look to the implementation of the function returned by slidein. Nothing from the prototype implementation of slidein jumps out at me as being incorrect. Try a JS debugger, such as Firebug or that built in to Safari or Chrome (the Chrome debugger offers a variety of breakpoint types, including breaking on DOM events).So then in order to avoid the global, if I replace the call to mbind by:
It still produces the same result. Can you explain what is the correct method and what I'm doing wrong? I know adding a class as you said is better, but I wanna know why my code fails.Code:$("#"+tp).bind('mouseleave', slidein(this));
Note that the line wouldn't work in mbind (even if you rename variable tp to sId) as mbind is invoked as a free function (i.e. not a method), so this in mbind refers to the global object (which is window in browsers; this is initially undefined when the function is called, so it's assigned the global object as per ECMAScript-262 10.4.3).
Pop quiz: what's this in an event handler?
Magic incantations are notoriously dangerous to alter. Forget to change something or change the wrong thing and you'll find yourself transported far to the North to the Land of Cutz, where customs are strange, misunderstandings are many and inconsistencies abound. See "magic number", sense 1. What happens if you discover a bug and need to change the states or state transition function? (On the subject of transition functions, unifying state transitions into a single function or an array of functions (indexed by the current state) is much easier to manage.) See also "Unnamed numerical constants" on Wikipedia and Magic Number in Portland Pattern Repository's wiki (for some cruel humor, read "Replace Magic Number With Symbolic Constant", also in the latter).Is there any disadvantage with that?
I LOVE numbers, whats wrong with them?
When it comes to computers, you have to be. They aren't capable of forgiving errors. This is codified in half of Postel's Law: "Be conservative in what you send; be liberal in what you accept."You're some sort of a perfectionist ain't you? Well, personally I like being one at times, but you are way ahead.