Javascript code freezes the browser -
i'm trying make function generates duplicated css properties html class use. function works in 3 steps.
1 - console, create object :
var obj = new module('prefix', 'suffix');
2- add couple of properties :
obj.addproperty('width', 'px', 2); obj.addproperty('height', 'px', 2);
3 - run cloning process :
obj.clone('15', '3');
but than, freezes no apparent reason. here's full code :
<script> window.cloner_module = function(prefix, suffix) { this.properties = [] this.prefix = prefix; this.suffix = suffix; this.addproperty = function(option, type, side) { var array = []; array.push(option, type, side); this.properties.push(array); } this.clone = function(max, step) { var array = []; var entry_count = 0; var innermodulearray = []; var modulearray = []; var property; var option; var type; var side; var value; var string = ""; (var = 0; < max; + step) { innermodulearray = []; modulearray = []; modulearray.push('.' + prefix + + suffix + '{'); (var y = 0; y < this.properties.length; y++) { property = this.properties[y]; option = property[0]; type = property[1]; side = property[2]; value; if (!side) { value = i; } else if (side == '1') { value = type + i; } else if (side == '2') { value = + type; } else { console.log('"side" property must between 0 , 2'); } string = option + ": " + value + "; "; innermodulearray.push(string); } modulearray.push(innermodulearray); modulearray.push('}'); array.push(modulearray); entry_count++; } this.clones = array; this.last_entry_count = entry_count; this.last_step_registered = step; this.last_max_registered = max; } } </script>
your code entering infinite loop result of for
loop, in turn causing browser freeze. core problem line:
for (var = 0; < max; + step)
here final statement equal 3 (0 + 3), loop never finish. want change to:
for (var = 0; < max; += step)
this edit continuously increase i
step
each iteration, original intention.
Comments
Post a Comment