Blog Archives

String StartsWith and EndsWith in JavaScript

The following are a simple implementation checking whether a string starts with a prefix or ends with a suffix in JavaScript. Here we use indexOf() method of JavaScript String object. Syntax: string.indexOf(search, start) Parameters: search is the string to search

Tagged with: , ,
Posted in JavaScript

Detect Image Loading Error with jQuery

The following JavaScript code shows how to detect image loading error using jQuery. It uses bind to attach a handler to the “error” event for all image elements. Using ajax, we can log or handle such events. Suppose we have

Posted in JavaScript

Rotating Street View Panorama using Google Maps

We can use Google maps street view to build a simple virtual tour, namely automatically rotating street view panorama. For the setup, we need a specific “div” element holding the panorama. The solution for automatic rotating is using JavaScript “window.setInterval”

Tagged with: , , , ,
Posted in JavaScript, Web

JavaScript Encapsulation: Privacy and Data Hiding

JavaScript does not have syntax-level encapsulation. All properties of an object are visible. However, there do exist various patterns to ensure data encapsulation. Singletons and the Module Pattern The following code creates one singleton object using an object literal. JavaScript

Tagged with: , , ,
Posted in JavaScript, Web