Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using __{lookup,define}{G,S}etter__ #76

Merged
merged 1 commit into from
Feb 13, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions components/g-component.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,24 @@
}
}

function getPropertyDescriptor(object, name) {
if (object == null)
return undefined;
var pd = Object.getOwnPropertyDescriptor(object, name);
return pd || getPropertyDescriptor(Object.getPrototypeOf(object));
}

// copy property 'name' from src to obj
var copyProperty = function(name, src, obj) {
var g = src.__lookupGetter__(name);
if (g) {
obj.__defineGetter__(name, g);
} else {
obj[name] = src[name];
}
var s = src.__lookupSetter__(name);
if (s) {
obj.__defineSetter__(name, s);
}
var pd = getPropertyDescriptor(src, name);
Object.defineProperty(obj, name, pd);
};

// copy all properties from inProps (et al) to inObj
var mixin = function(inObj/*, inProps, inMoreProps, ...*/) {
var obj = inObj || {};
var p$ = Array.prototype.slice.call(arguments, 1);
for (var i=0, p; (p=p$[i]); i++) {
for (var i = 1; i < arguments.length; i++) {
var p = arguments[i];
for (var n in p) {
copyProperty(n, p, obj);
}
Expand All @@ -250,11 +249,16 @@
}
};

function hasGetter(object, name) {
var pd = getPropertyDescriptor(object, name);
return !!(pd && pd.get);
}

// make inSource[inName] available on inTarget as a getter/setter
// pair or a method bound to this.$protected
function publishProperty(inSource, inName, inTarget) {
// access property value (unless it is a getter itself)
var value = (!inSource.__lookupGetter__(inName)) && inSource[inName];
var value = !hasGetter(inSource, inName) && inSource[inName];
if (typeof value == 'function') {
inTarget[inName] = function() {
return value.apply(this.$protected, arguments);
Expand Down