Jon Simon's Personal Development Site
In this quick tutorial I'm going to go through a simple example of how you can extend an object in JavaScript. The first thing you'll need to do is get jQuery, which you can get here: http://docs.jquery.com/Downloading_jQuery.
Once you have that included in your project, you can go ahead and extend an object by doing the following:
Are you looking to search a directory for a specific file, or just display contents of a directory? Then I think this snippet of code will be useful.
Do you need to format dates using php? Well, it's easy as cake - read on for some example code.
If you are looking for it to spit out the mm/dd/yyyy format, this is how it's done.
If you're trying to programmatically figure out how to move or drag a view with your finger, then read on.
I was looking for a solution to this problem just the other day, and couldn't really find that much. What I needed was a view that you could move with your finger, and upon lifting the finger, it would snap into place at a set location. Seeing as I couldn't find anything like this, I decided to write my own custom view, which did just that.
The view I wrote extends UIImageView, but you can change that to UIView if you want. So how does this work you ask? Well, it basically takes a topLock, bottomLock, and whether it's moving on the x axis or not (if not, then it uses the y axis). The top lock is the x(or y) point where the view will lock into place, and same with the bottom lock. And how that works is that it'll check which one is closest, and lock it into that spot. So here's an example, if you drag the view up on the y axis all the way to the top and let go, it'll move it to the closest lock point (which will most likely be the top lock. This will also give that nice swing-back (gravity) effect that you see on the iPhone tableviews.
I'm going to be referring to iOS related Objective-C, as the blocks were just released in version 4, so it's an interesting topic.
Before the blocks functionality, the typical way to do a callback would be to pass the delegate of the object which would be called to the worker object. Once the worker object finished the task, it would then reference a specific method (defined by the protocol), which executes the callback code. This approach works fine, but gets very bloated when you need to do certain kinds of tasks - not going to be getting to the protocols vs blocks in this article though. They do both serve their own purposes, and I'm just going to be getting into the relations they have to the Java anonymous classes.
view all articles
