Web Developer

Etiqueta: Javascript

Singleton Pattern en Javascript

La finalidad del patrón de diseño Singleton es garantizar que una clase tiene sólo una instancia y proporcionar un punto de acceso global a ella.

Un ejemplo:

var PlasmikSingleton = (function() {
 var instance = null;

 function initialize() {
  var url = "http://www.javierms.com/blog";
  this.getUrl = function() {
  return url;

 return new function() {
  this.getInstance = function() {
  if (instance == null) {
  instance = new initialize();
  instance.constructor = null;
  return instance;

var singleton = PlasmikSingleton.getInstance();
alert("URL -> "+singleton.getUrl());

JavaScript security errors in Adobe Air

Event callbacks assigned through onevent attributes in innerHTML and outerHTML statements

When you use innerHTML or outerHTML to add elements to the DOM of a document, any event callbacks assigned within the statement, such as onclick or onmouseover, are ignored. No security error is generated. Instead, you can assign an id attribute to the new elements and set the event handler callback functions using the addEventListener() method.

For example, given a target element in a document, such as:

<div id="container"></div>

Replace statements such as:

document.getElementById('container').innerHTML =
    '<a href="#" onclick="code()">Click Me</a>';


document.getElementById('container').innerHTML = '<a href="#" id="smith">Click Me</a>';
smith = document.getElementById('smith');
if(smith!=null) smith.addEventListener("click", function() { code(); });

by Help Adobe


Tema por Anders NorenArriba ↑