Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update the README.

  • Loading branch information...
commit badda738f4e55550ee02477ddc9f19540d289621 1 parent d9b2372
@creationix authored
Showing with 31 additions and 22 deletions.
  1. +31 −22 README.markdown
View
53 README.markdown
@@ -6,16 +6,16 @@ This simple js library adds three functions to Object.prototype and one to Funct
All functions added to `Object.prototype` are usable from any object in JavaScript.
-### Object.prototype.forEach
+### Object.prototype.forEach(callback[, thisObject])
This is the most useful of the additions. It allows you to forEach over an `Object` instance's local properties and values just like you can already do with `Array` instances.
require('proto');
({name: "Tim", age: 28}).forEach(function (value, key) {
- sys.puts(key + " = " + JSON.stringify(value));
+ console.log(key + " = " + JSON.stringify(value));
});
-### Object.prototype.map
+### Object.prototype.map(callback[, thisObject])
This works like forEach, except returns an `Array` instance with the returned values of the function calls.
@@ -25,27 +25,36 @@ This works like forEach, except returns an `Array` instance with the returned va
});
// pairs is ["name = Tim", "age = 28"]
-### Object.prototype.mixin
+### Object.prototype.new(args...)
-Does a shallow copy from another object into this one.
+Creates a new version of the current object and calls it's `initialize` function if one exists with the same arguments passed to new.
require('proto');
- GLOBAL.mixin(require('sys'));
- puts("Hello World");
-
-## Function.prototype
-
-Functions added to `Function.prototype` are available to any JavaScript function.
-
-### Function.prototype.curry
-
-Partially applies a function and returns a new function that accepts the remaining arguments.
+ var Rectangle = {
+ initialize: function initialize(width, height) {
+ this.width = width;
+ this.height = height;
+ },
+ get area() {
+ return this.width * this.height;
+ }
+ };
+
+ var rect = Rectangle.new(2, 4);
+ console.log(rect.area);
+
+### Object.prototype.extend(newObject)
+
+Sets the current object as the prototype to the passed in object and returns the new passed in object.
+
+ // Assuming the code from above
+ var Square = Rectangle.extend({
+ initialize: function initialize(side) {
+ this.width = side;
+ this.height = side;
+ }
+ });
+ var square = Square.new(15);
+ console.log(square.area);
- require('proto');
- var fs = require('fs');
- var sys = require('sys');
- // Create a curried version of the readFile function
- var loader = fs.readFile.curry("myfile.txt");
- // Then finish the application of the function
- loader(sys.debug);
Please sign in to comment.
Something went wrong with that request. Please try again.