Created
July 17, 2015 06:57
-
-
Save dbonillaf/9e5367a6351d522ed6ba to your computer and use it in GitHub Desktop.
Intentando entender el paso por referencia en JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var fs = require('fs'); | |
var handlebars = require('handlebars'); | |
var source = new Buffer(10); | |
// El objeto source no contiene nada | |
console.log(source.toString('utf-8')); | |
fs.readFile('home.html', function(error, source){ | |
if(error) { | |
console.log(error); | |
} else { | |
// El objeto source contiene los datos del fichero | |
console.log(source.toString('utf-8')); | |
} | |
}); | |
var app = express(); | |
app.get('/', function (req, res) { | |
// El objeto source VUELVE a no contener nada | |
res.send(source.toString('utf-8')); | |
}); | |
var server = app.listen(3000, function () { | |
var host = server.address().address; | |
var port = server.address().port; | |
console.log('Backend listo para combatir en http://%s:%s', host, port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No hay un paso por referencia del primer
source
que declaras. Es simplemente otra variable. Es como si en Java haces esto: