add classProps declaration to simplify/nicen up class property defining - closes #88

This commit is contained in:
Sebastian McKenzie
2014-11-03 13:36:23 +11:00
parent c8139317ee
commit c17878913b
13 changed files with 95 additions and 40 deletions

View File

@@ -1,5 +1,12 @@
"use strict";
var _slice = Array.prototype.slice;
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _extends = function (child, parent) {
child.prototype = Object.create(parent.prototype, {
constructor: {
@@ -27,7 +34,17 @@ var Test = function(Foo) {
_extends(Test, Foo);
Object.defineProperties(Test.prototype, {
_classProps(Test, {
foo: {
writable: true,
value: function() {
Foo.foo.call(this);
Foo.foo.call.apply(Foo.foo, [this].concat(_slice.call(arguments)));
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_slice.call(arguments)));
}
}
}, {
test: {
writable: true,
@@ -39,17 +56,5 @@ var Test = function(Foo) {
}
});
Object.defineProperties(Test, {
foo: {
writable: true,
value: function() {
Foo.foo.call(this);
Foo.foo.call.apply(Foo.foo, [this].concat(_slice.call(arguments)));
Foo.foo.call.apply(Foo.foo, [this, "test"].concat(_slice.call(arguments)));
}
}
});
return Test;
}(Foo);

View File

@@ -1,5 +1,10 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _extends = function (child, parent) {
child.prototype = Object.create(parent.prototype, {
constructor: {
@@ -13,7 +18,6 @@ var _extends = function (child, parent) {
child.__proto__ = parent;
};
var Test = function(Foo) {
var Test = function Test() {
Foo.prototype.test.whatever();
@@ -22,7 +26,7 @@ var Test = function(Foo) {
_extends(Test, Foo);
Object.defineProperties(Test, {
_classProps(Test, {
test: {
writable: true,
@@ -30,7 +34,7 @@ var Test = function(Foo) {
return Foo.wow.call(this);
}
}
});
}, null);
return Test;
}(Foo);

View File

@@ -1,9 +1,14 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = function() {
var Test = function Test() {};
Object.defineProperties(Test.prototype, {
_classProps(Test, null, {
test: {
get: function() {
return 5 + 5;
@@ -16,4 +21,4 @@ var Test = function() {
});
return Test;
}();
}();

View File

@@ -1,9 +1,14 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = function() {
var Test = function Test() {};
Object.defineProperties(Test.prototype, {
_classProps(Test, null, {
test: {
get: function() {
return 5 + 5;
@@ -12,4 +17,4 @@ var Test = function() {
});
return Test;
}();
}();

View File

@@ -1,9 +1,14 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = function() {
var Test = function Test() {};
Object.defineProperties(Test.prototype, {
_classProps(Test, null, {
test: {
writable: true,
@@ -14,4 +19,4 @@ var Test = function() {
});
return Test;
}();
}();

View File

@@ -1,9 +1,14 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = function() {
var Test = function Test() {};
Object.defineProperties(Test.prototype, {
_classProps(Test, null, {
test: {
set: function(val) {
this._test = val;
@@ -12,4 +17,4 @@ var Test = function() {
});
return Test;
}();
}();

View File

@@ -1,9 +1,14 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var A = function() {
var A = function A() {};
Object.defineProperties(A, {
_classProps(A, {
a: {
writable: true,
value: function() {}
@@ -13,7 +18,7 @@ var A = function() {
get: function() {},
set: function(b) {}
}
});
}, null);
return A;
}();
}();

View File

@@ -1,9 +1,14 @@
"use strict";
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = function() {
var Test = function Test() {};
Object.defineProperties(Test.prototype, {
_classProps(Test, null, {
bar: {
get: function() {
throw new Error("wow");
@@ -15,4 +20,4 @@ var Test = function() {
}();
var test = new Test();
test.bar;
test.bar;

View File

@@ -4,7 +4,7 @@
"column": 11
},
"generated": {
"line": 9,
"line": 17,
"column": 15
}
}]