如何使用var applyCtor = function(){
var tempCtor = function() {};
return function(ctor, args){
tempCtor.prototype = ctor.prototype;
var instance = new tempCtor();
ctor.prototype.constructor.apply(instance,args);
return instance;
}
}();
var CarClass = (function (){
function car(doorsClass){
this.doorsClass = doorsClass;
}
car.prototype.color = function(color){
console.log('Car color is '+color);
}
car.prototype.doorsNum = function(doorsNum){
console.log('Car has '+this.doorsClass.doors(doorsNum)+' doors');
}
return car;
})(); //<-- execute your module
var DoorsClass = (function (){
function doors(){ }
doors.prototype.doors = function(num){
return num;
}
return doors;
})();//<-- execute your module
// Apply the given ctor with arguments.
var carInstance = applyCtor(CarClass,[new DoorsClass()]);
carInstance.color('red');
carInstance.doorsNum(4);
?
以下是我的尝试:
node.js
但没有任何反应
答案 0 :(得分:0)
You must specify a file from the local file system. So I advise
var fs = require('fs');
fs.writeFile("/tmp/test", "some text in file", function(err) {
if(err) { return console.log(err); }
console.log("The file was saved!");
});
send the file
var unirest = require('unirest');
unirest.post('127.0.0.1/upload')
.headers({'Content-Type': 'multipart/form-data'})
.attach('file', '/tmp/test')
.end(function (response) {
console.log(response.body);
});