NODEJS(10)Book Read - hands-on-nodejs.pdf - pseudo class
3. Making Modules
A pseudo-class
var Line = function(x1, y1, x2, y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
};
Line.prototype.length = function() {
return Math.sqrt(
Math.pow(Math.abs(this.x1 - this.x2),2) +
Math.pow(Math.abs(this.y1 - this.y2),2)
);
};
module.exports.create = function(x1, y1, x2, y2) {
return new Line(x1, y1, x2, y2);
};
That is a pseudo-class which named Line, when we use it we can do like this,
var Line = require(‘./line’);
var line = Line.create(2,4,10,15);
console.log(‘this line length is ‘ + line.length());
A psedo-class that inherits
var util = require(‘util’);
var EventEmitter = require(‘events’).EventEmitter;
var Line = function(x1, y1, x2, y2) {
…snip...
};
util.inherits(Line, EventEmitter);
Line.prototype.length = function() {
…snip...
};
node_modules and NPM bundle
I can commit my modules to git, and then, who plan to use it can do like this.
For example, this is for the tool AES, package.json
{
"name" : "sillycat-aes",
"version" : "0.1.0",
"description" : "Module for AES encryption and descritpion",
"main" : "lib/app.js"
}
When we plan to use it, we do like this, package.json
{
"name" : "sillycat-platform",
"version" : "0.1.0",
"description" : "Sillycat Platform, provide all kinds of tools.",
"main" : "lib/app.js",
"dependencies" : {
"sillycat-aes" : "git://github.com/luohuazju/sillycat-aes.git"
}
}
Just use NPM command to install that.
>npm install
References:
package.json
http://docs.spmjs.org/doc/package
http://blog.uifanr.com/2013/03/13/478
http://blog.csdn.net/zimin1985/article/details/18958741
- 浏览: 2560892 次
- 性别:
- 来自: 成都
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
相关推荐
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
nodejs010-nodejs-read-1.0.5-1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-read-installed-0.2.4-1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-read-package-json-1.1.6-1.el6.centos.alt.noarch.rpm
nodeJs 12.22.12-x64-windows版本 nodeJs 12.22.12-x64-windows版本 nodeJs 12.22.12-x64-windows版本 nodeJs 12.22.12-x64-windows版本 nodeJs 12.22.12-x64-windows版本
nodejs010-nodejs-nopt-2.1.2-1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-lockfile-0.4.2-1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-asn1-0.1.11-3.1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-request-2.25.0-1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-osenv-0.0.3-6.el6.centos.alt.noarch.rpm
nodejs010-nodejs-sntp-0.2.4-1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-rimraf-2.2.6-1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-mongodb-1.3.19-3.2.el6.centos.alt.noarch.rpm
nodejs010-nodejs-slide-1.1.5-1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-sha-1.2.1-1.1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-retry-0.6.0-6.el6.centos.alt.noarch.rpm
nodejs010-nodejs-npmlog-0.0.6-1.el6.centos.alt.noarch.rpm
nodejs010-nodejs-promzard-0.2.0-7.el6.centos.alt.noarch.rpm
nodejs010-nodejs-mime-1.2.11-3.el6.centos.alt.noarch.rpm
nodejs010-nodejs-once-1.3.0-1.el6.centos.alt.noarch.rpm