Closed GoogleCodeExporter closed 8 years ago
Please don't use "__defineGetter__", its for FireFox and I think it already
deprecated. does not support by IE9 too.
The following syntax is working in all modern browser and IE9 too.
Object.defineProperty(object, "propertyName", {
get:function () {
return this._value;
},
set:function (value) {
this._valye = value;
}
});
the JSON format work in all modern browser including IE9.
Original comment by Madnik7@gmail.com
on 4 Aug 2012 at 10:11
Original comment by DanelK...@gmail.com
on 28 Aug 2012 at 6:54
I just fix my sample
var Foo = function()
{
this._test = 1;
};
Object.defineProperty(Foo.prototype, "test", {
get:function () {
return this._test;
},
set:function (value) {
this._test = value;
}
});
Original comment by Madnik7@gmail.com
on 15 Sep 2012 at 10:11
Please don't forget to set "enumerable : true"
Object.defineProperty(Foo.prototype, "test", {
get:function () {
return this._test;
},
set:function (value) {
this._test = value;
},
enumerable : true //*** HERE
});
Original comment by Madnik7@gmail.com
on 15 Sep 2012 at 6:48
I find serious problem in SharpKit. the following approach generally not work
for new get set properties.
ce.prototype[p], ce2.prototype[p] will call property function and value not its
and not copy its property handler, it cause serious issue. I wonder how you
going to fix it! :(
if (typeof($Inherit)=='undefined') {
var $Inherit = function(ce, ce2) {
for (var p in ce2.prototype)
if (typeof(ce.prototype[p]) == 'undefined' || ce.prototype[p]==Object.prototype[p])
ce.prototype[p] = ce2.prototype[p]; /**
for (var p in ce2)
if (typeof(ce[p]) == 'undefined')
ce[p] = ce2[p];
ce.$baseCtor = ce2;
}
}
Original comment by Madnik7@gmail.com
on 16 Sep 2012 at 10:55
I find Object.Create is naively support inheritance, but I don't have idea how
to use it. mean while I found a solution same as your $inherit method. I didn't
test it much.
$inherit(ce, ce2)
{
var props = Object.getOwnPropertyNames(ce2.prototype);
for (var i = 0; i < props.length; i++)
if (typeof(Object.getOwnPropertyDescriptor(ce.prototype, props[i])) == 'undefined')
Object.defineProperty(ce.prototype, props[i], Object.getOwnPropertyDescriptor(ce2.prototype, props[i]));
for (var p in ce2)
if (typeof(ce[p]) == 'undefined')
ce[p] = ce2[p];
ce.$baseCtor = ce2;
}
regards
Original comment by Madnik7@gmail.com
on 16 Sep 2012 at 12:22
getOwnPropertyNames is very nice for new browsers, although it's not supported
on older browsers... only IE9+
But I will investigate this issue further
Original comment by DanelK...@gmail.com
on 17 Sep 2012 at 12:30
Original comment by DanelK...@gmail.com
on 23 Sep 2012 at 5:41
Original comment by sebastia...@gmail.com
on 26 Sep 2012 at 11:41
Original comment by sebastia...@gmail.com
on 27 Sep 2012 at 6:43
Found two issue in v4:30
1)
Assembly NativeProperty does not affect!
[assembly: JsProperty(NativeProperty = true)]
2)
Your defined property has not set enumerable to true. enumerable: false"
I wrote in Sharpkit Group too:
https://groups.google.com/forum/#!topic/sharpkit/MTxkEaURj7s
Still I couldn't use it , currently I use my own implementation, but it is not
welcome. My implementation is here:
http://code.google.com/p/shetabebookextras/source/browse/trunk/Agents/Html/Commo
n/SharpKitMiss.cs
Regards
Original comment by Madnik7@gmail.com
on 4 Oct 2012 at 7:37
fixed
Original comment by sebastia...@gmail.com
on 4 Oct 2012 at 11:08
Thanks for new update. I found you create native property for static
propertiest too and I didn't know that is possible, that's great but I found
the the issue in $inherit method while NativePropertiesEnumerable is true and
base class has static property.
here is new code to fix it:
regards
if (typeof ($Inherit) == 'undefined') {
var $Inherit = function (ce, ce2) {
if (typeof (Object.getOwnPropertyNames) == 'undefined') {
for (var p in ce2.prototype)
if (typeof (ce.prototype[p]) == 'undefined' || ce.prototype[p] == Object.prototype[p])
ce.prototype[p] = ce2.prototype[p];
for (var p in ce2)
if (typeof (ce[p]) == 'undefined')
ce[p] = ce2[p];
ce.$baseCtor = ce2;
} else {
var props = Object.getOwnPropertyNames(ce2.prototype);
for (var i = 0; i < props.length; i++)
if (typeof (Object.getOwnPropertyDescriptor(ce.prototype, props[i])) == 'undefined')
Object.defineProperty(ce.prototype, props[i], Object.getOwnPropertyDescriptor(ce2.prototype, props[i]));
props = Object.getOwnPropertyNames(ce2);
for (i = 0; i < props.length; i++)
if (typeof (Object.getOwnPropertyDescriptor(ce, props[i])) == 'undefined')
Object.defineProperty(ce, props[i], Object.getOwnPropertyDescriptor(ce2, props[i]));
ce.$baseCtor = ce2;
}
}
};
Original comment by Madnik7@gmail.com
on 15 Oct 2012 at 2:43
Original issue reported on code.google.com by
DanelK...@gmail.com
on 4 Aug 2012 at 9:01