An early issue I ran into with scope, and a common one, is the loss of scope of the “this” keyword in the closed function. For example, you might want to do a setInterval that references the object that created it. To do so, you can simply create a variable pointing to “this” and then use that in the closed function, like:
During my internship at RPM, we used classic ASP for server side scripting rather than the PHP I’m more used to. Classic ASP is missing functions for formatting dates, like PHP and *NIX shell have, for instance. SQL Server has the CONVERT function, but only has a limited number of output formats, at least for the older SQL Server version we had: Otherwise, it would be more efficient to format the data as it is coming from the database . I built two functions for date formatting based on the PHP and *NIX “date” formats for use on the HSGA site, where I had to format dates a certain way for a project. I don’t remember if I used it on other projects, but I think so.
Both functions take two parameters. The first is a date, as would come from a SQL Server “datetime” field. The second is a string that defines the output format. The first function uses a format string like the php date function. The long function is as follows (tabs are double spaces due to the width and length of the content):
In PHP, it is not quite as elegant, but almost. An array with key-value pairs is passed as the single argument for named argument mode. So you could call like this:
It’s rather simple to handle. I was even able to modify an already in use function to use one literal value parameter or the many that it originally used, simply by checking the arguments.length function property to see if it is one, and populating the appropriate variables if so. So to handle the properties, they are appended to the argument and accessed by the key in dot notation. Example function: