Skip to content
This repository

Added implement and extend to Class prototype #30

Closed
wants to merge 2 commits into from

2 participants

Daniel Buchner Sean McArthur
Daniel Buchner

No description provided.

Sean McArthur seanmonstar commented on the diff March 06, 2012
lib/shipyard/class/Class.js
@@ -9,6 +9,14 @@ var Accessor = require('../utils/Accessor'),
9 9
     merge = object.merge,
10 10
     extend = object.extend;
11 11
 
  12
+Function.prototype.extend = func.overloadSetter(function(key, value){
1
Sean McArthur Owner

No extending Function. I could see this being on Class, though the gain is small, since you can write all the methods for a class when you do new Class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sean McArthur seanmonstar commented on the diff March 06, 2012
lib/shipyard/utils/function.js
@@ -5,7 +5,7 @@ var typeOf = require('./type').typeOf;
5 5
 exports.noop = function noop() {};
6 6
 
7 7
 // Allows fn(params) -> fn(key, value) for key, value in params
8  
-exports.overloadSetter = function(fn) {
  8
+var overloadSetter = exports.overloadSetter = function(fn) {
1
Sean McArthur Owner

These vars aren't used anywhere else in the module, so there's no need for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sean McArthur seanmonstar closed this March 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
8  lib/shipyard/class/Class.js
@@ -9,6 +9,14 @@ var Accessor = require('../utils/Accessor'),
9 9
     merge = object.merge,
10 10
     extend = object.extend;
11 11
 
  12
+Function.prototype.extend = func.overloadSetter(function(key, value){
  13
+	this[key] = value;
  14
+});
  15
+
  16
+Function.prototype.implement = func.overloadSetter(function(key, value){
  17
+	this.prototype[key] = value;
  18
+});
  19
+	
12 20
 function Class(params) {
13 21
     function klass() {
14 22
         reset(this);
20  lib/shipyard/utils/array.js
... ...
@@ -1,13 +1,11 @@
1  
-var typeOf = require('./type').typeOf;
2  
-
3  
-var slice = Array.prototype.slice;
  1
+var typeOf = require('./type').typeOf,
  2
+	slice = Array.prototype.slice;
4 3
 
5 4
 function isArrayLike(item) {
6 5
 	var type = typeOf(item);
7 6
 	return item != null && item.length && type !== 'function' && type !== 'string';
8 7
 }
9 8
 
10  
-
11 9
 exports.from = function from(item) {
12 10
     var type = typeOf(item);
13 11
     if (isArrayLike(item)) {
@@ -28,3 +26,17 @@ exports.flatten = function flatten(arr) {
28 26
 	}
29 27
 	return flatty;
30 28
 };
  29
+
  30
+var contains = exports.contains = function(array, item, from){
  31
+	return array.indexOf(item, from) != -1;
  32
+}
  33
+
  34
+var include = exports.include = function(array, item){
  35
+	if (!contains(array, item)) array.push(item);
  36
+	return array;
  37
+};
  38
+
  39
+var combine = exports.combine = function(array, items){
  40
+	for (var i = 0, l = items.length; i < l; i++) include(array, items[i]);
  41
+	return array;
  42
+};
6  lib/shipyard/utils/function.js
@@ -5,7 +5,7 @@ var typeOf = require('./type').typeOf;
5 5
 exports.noop = function noop() {};
6 6
 
7 7
 // Allows fn(params) -> fn(key, value) for key, value in params
8  
-exports.overloadSetter = function(fn) {
  8
+var overloadSetter = exports.overloadSetter = function(fn) {
9 9
 	return function overloadedSetter(keyOrObj, value) {
10 10
 		if (typeOf(keyOrObj) !== 'string') {
11 11
 			for (var key in keyOrObj) {
@@ -19,7 +19,7 @@ exports.overloadSetter = function(fn) {
19 19
 };
20 20
 
21 21
 // Allows fn(list) -> return fn(key) for key in list
22  
-exports.overloadGetter = function(fn) {
  22
+var overloadGetter = exports.overloadGetter = function(fn) {
23 23
     return function overloadedGetter(key) {
24 24
         var me = this;
25 25
         if (arguments.length > 1) {
@@ -40,4 +40,4 @@ exports.lazy = function(obj, key, setup) {
40 40
 		obj[key] = setup.apply(this, arguments);
41 41
 		obj[key].apply(this, arguments);
42 42
 	};
43  
-};
  43
+};
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.