How to access property inside function constructor javascript -
i need manipulate html tags through class such:
/* * begin: html class */ html = function(el, property) { // construct this.el = el; this.property = new array; var html = document.createelement(el); this.element = function() { return html; }; html.objects.push(this); if (typeof property == "object") (i in property) this.addproperty(i, property[i]); }; html.objects = new array; // registers new html objects. // adds new property html current element. html.prototype.addproperty = function(name, value) { this.property[name] = value; this.gethtml()[name] = value; }; // retrieves current html element. html.prototype.gethtml = function() { return this.element(); }; // clones current html objects same construct arguments. html.prototype.clone = function() { return new html(this.el, this.property); }; /* * end: html class */
each time new html(...)
called, newly created instance must stored within html.objects
static property of html role keep track of html objects. when reaches html.objects.push(this);
return undefined property error. after, tried call html.objects
in firebug , defined. function(...) { ... }
called @ instantiation, shouldn't able access html.objects
property?
thanks.
the proprety html.objects
doesn't exists because in constructor's scope html
variable have defined here:
var html = document.createelement(el);
so, when make call:
html.objects.push(this);
you trying access proprey of declared html
variable.
in fact, if try replace first line with:
var html_inner = document.createelement(el);
it'll work
Comments
Post a Comment