JavaScript
Firefox 3.6.13 crash mit localStorage.removeItem
by Nox on Feb.16, 2011, under JavaScript
Probleme mit folgendem Code:
-
jQuery(function($) {
-
$(window).bind('storage', function(_){
-
// Verfy the Storage-Interface
-
if(window.localStorage instanceof Storage)
-
window.localStorage.length // Line is needed, somehow
-
});
-
-
// Not sure if this is needed,
-
// but we should have an A before removing it
-
window.localStorage.setItem('A', JSON.stringify(123));
-
-
// Crash FF!
-
window.localStorage.removeItem('A');
-
});
Wie in Zeile 1 zu sehen, es wird eine aktuellere jQuery Version gebraucht. Aktuellere weil ich es nicht mit älteren probiert habe. Geladen ist momentan diese hier: jQuery 1.5.0
Getestet ist es ausserdem nur im aktuellen Firefox 3.6.13.
Was passiert:
Es wird ein Element aus dem localStorage entfernt und, nachdem das passiert ist, versucht der GarbageCollector irgendwie einen Pointer auf das Element zu nutzen. Das schlägt scheinbar fehl, da wir alles schon per Hand gelöscht haben.
Nun stürzt bei mir leider dabei der Firefox ganz ab... Schade
node.js and global objects
by Nox on Jan.10, 2011, under JavaScript, node.js
Today I had a little problem with a node.js app.
I tried to seperate some parts of the app to different files. The problem that I ran into was that the app was controlled by a config file which was loaded synchronously and then carried on with the app.
-
var config = lib.extend({
-
name: 'unnamed!',
-
port: 3000,
-
mountpoint: '/ft',
-
timeout: 250,
-
wait: 1500,
-
path: './Data'
-
}, require('./' + config));
Now after seperating the server and client parts of this app into two different files I had no access anymore to the config file without always carrying the config object with everything. This let me to a simple solution.
-
var EventEmitter = require('events').EventEmitter;
-
-
var system = new EventEmitter;
-
-
module.exports = system;
-
var system = require('./system');
-
system.config = config;
-
/* now every other code has access to the config
-
via system.config or through system.on('initialize', function(config) {});
-
*/
-
system.emit('initialize', config);
Oh... and the reason for this junk is... The global-object does not seem to work. I tried global.config = config, and it did not work.
Have fun with this
Nox
jQuery IE window.resize fix
by Nox on Nov.05, 2008, under JavaScript
Ich habe mich vor einigen Tagen mal wieder mit dem Internet Explorer herumgeschlagen. Anders als der Firefox triggert dieser das resize-Event nämlich während der Mausbewegung, und nicht erst wenn es abgeschlossen ist.
Dies bedeutet für eine AJAX Anwendung die das resize-Event abfängt Performanzprobleme, denn diese wird nun andauernd getriggert.
Da ich derzeit viel mit jQuery arbeite habe ich mir die Mühe gemacht einen Fix dafür zu schreiben.
if(jQuery.browser.msie) (function ($) {
var bind = jQuery.fn.bind;
jQuery.fn.bind = function( type, data, fn ) {
if(type != "resize")
return bind.apply(this, [type, data, fn]);
var timer = 1;
var args = null;
var handler = function(e, y) {
timer = 1;
(fn || data).apply(this, args);
};
bind.apply(this, [type, data, function() {
if (timer) clearTimeout(timer);
args = arguments;
timer = setTimeout(handler, 150);
}]);
return this;
}
})(jQuery);
Was das Skript macht, es überschreibt im Falle das jQuery einen MS-IE findet. Es wird das alte bind abgespeichert und mit einer extra Funktion aufgerufen die erst bis 150 zählt bevor es das Event weiterleitet, sollte es zu früh getriggert werden dann fängt die Funktion wieder von vorne an zu zählen.
Problem gelöst.