Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rename initialize to constructor and other cleanups.

  • Loading branch information...
commit e23f7ad6beb1a203e1754d222ae071362b9678da 1 parent 7934ddc
@creationix authored
View
3  README.markdown
@@ -11,8 +11,7 @@ Creating a database is easy, you just call the nStore function to generate a col
// Load the library
var nStore = require('nstore');
// Create a store
- var users = Object.create(nStore);
- users.initialize('data/users.db', function () {
+ var users = nStore.new('data/users.db', function () {
// It's loaded now
});
View
14 lib/class.js
@@ -3,17 +3,19 @@
var Class = module.exports = Object.create(Object.prototype, {
// Implement extend for easy prototypal inheritance
extend: {value: function extend(obj) {
+ if (obj === undefined) return Object.create(this);
obj.__proto__ = this;
- // Lock the object to be used only as a prototype
- Object.freeze(obj);
+ Object.freeze(obj); // Lock the prototype to enforce no changes
return obj;
}},
+
// Implement new for easy self-initializing objects
- new: {value: function () {
+ new: {value: function new_() {
var obj = Object.create(this);
- if (obj.initialize) obj.initialize.apply(obj, arguments);
- // Lock the object down so the fields are static
- Object.seal(obj);
+ if (typeof obj.constructor === 'function') obj.constructor.apply(obj, arguments);
+ Object.seal(obj); // Lock the object down so the fields are static
return obj;
}}
+
});
+
View
3  lib/hash.js
@@ -1,7 +1,8 @@
+
// A Hash is an interable object
var Hash = module.exports = Object.create(Object.prototype, {
// Make for easy converting objects to hashes.
- new: {value: function initialize(value) {
+ new: {value: function (value) {
value = value || {};
value.__proto__ = Hash;
return value;
View
2  lib/nstore.js
@@ -14,7 +14,7 @@ var nStore = module.exports = Class.extend({
// Set up out local properties on the object
// and load the datafile.
- initialize: function initialize(filename, callback) {
+ constructor: function constructor(filename, callback) {
this.filename = filename;
this.fd = null;
this.index = Hash.new();
View
2  lib/queue.js
@@ -3,7 +3,7 @@ var Class = require('./class');
// If a large number of writes gets queued up, the shift call normally
// eats all the CPU. This implementes a faster queue.
var Queue = module.exports = Class.extend({
- initialize: function initialize() {
+ constructor: function constructor() {
if (this === Queue) throw new Error("Cann't use Queue directly");
this.tail = [];
this.head = Array.prototype.slice.call(arguments);
Please sign in to comment.
Something went wrong with that request. Please try again.