Prototypal inheritances works by checking objects for properties and, not
finding them, inspecting the object from which that parent inherits for
them. In this way all your instances of your classes share methods and
properties until you assign them something else. So:
var Widget = new Class({
foo: 'bar'
});
var x = new Widget();
x.foo == 'bar' == true;
in the above example, x does not have a property called "foo" but instead
inherits from the object passed to Class when Widget is constructed. If you
later assign a value to x, even if you assign it "bar" again, x will have
it's own property.
On Tue, Aug 25, 2009 at 4:23 AM, woomla <[email protected]> wrote:
>
> Shouldn't this.val in function initialize own the property 'a'?
>
> Mootools more URI.schemes also doesn't own its properties like http,
> https etc.
> But Swiff.options does own all its properties.
>
> On 25 aug, 11:10, Thierry bela nanga <[email protected]> wrote:
> > I guess
> >
> > TFalse.val //undefined
> > TFalse.prototype.val //defined
> >
> > ?
> >
> >
> >
> > On Tue, Aug 25, 2009 at 10:03 AM, woomla <[email protected]> wrote:
> >
> > > Running the code below shows that class TFalse.val.hasOwnProperty('a')
> > > === false.
> > > Why is that? Can I not use hasOwnProperty?
> >
> > > e.q. URI.schemes does not own its properties http, https etc.
> > > It seems that property options does own its properties.
> >
> > > Should I use hasOwnProperty in this case? I use it in this way:
> > > for (key in this.val)
> > > {
> > > if (this.val.hasOwnProperty(key))
> > > {
> > > //do something with this.val[key]
> > > }
> > > }
> >
> > > code:
> >
> > > var TFalse, TTrue;
> >
> > > TFalse = new Class(
> > > {
> > > val:
> > > {
> > > a: 0
> > > },
> > > initialize: function ()
> > > {
> > > console.log(this.val.hasOwnProperty('a'));
> > > }
> > > });
> >
> > --http://tbela99.blogspot.com/
> >
> > fax : (+33) 08 26 51 94 51
>