Cuaderno

node v10.24.1
version: 4.0.0
endpointsharetweet
number
"Trabajando con la version de node" + process.version console.log("hola a todos")
typeof(23)
typeof({})
require("roman-numeral").convert(2021)
v= 23; console.log(v); typeof(v);
v = 3 + 3*4
27 % 5
//string Math.pi + Math.log(123)
console.log(v.lenght); v.lenght
Number
v = 23; console.log(v); typeof(v);
v = 3 + 2*3/5
27 % 5
Math.PI
Math.sin(23)
string
v = "Hola"; console.log(v); typeof(v);
v.length
console.log(v.length); v+"Mundo"
Array
v[2]
v = [1,2,4,"str",[3]]; console.log(v); typeof(v);
Iteración de un array: for
for (var i=0; i<v.length; i++){ console.log(""+i+" -> "+v[i]); }
Usando map
a = [1,4,7,3,9]; a.map(Math.sqrt)
v = true console.log(v) typeof(v);
v && false || ! v
object: conjunto de parejas prepiedad: valor
v = {} v = {prop1:"valor1"}
v.prop1
Function
v = function(x){ console.log("Ejecutando función con argumento"+x); return 2 * x; } console.log(v); typeof(v);
Undefined
var z console.log(z); typeof(z);
null
var n = null console.log(n); typeof(n);
Crear un objeto directamente
var neo = {npatas: 4,tienepelo: true}
function Gato(){ this.npatas=4; this.tienepelo=true; } micifu = new Gato() micifu
function Mamifero(name){ this.npatas=4; this.nombre = name; this.tienePelo=true; } Gato = function(name){ obj = new Mamifero(name); obj.especie = "gato" return obj; } micifu = new Gato ("Micifú") micifu
Herencia
Mamifero = function (name){ this.npatas=4; this.nombre = name; this.tienePelo=true; this.poneHuevos= false; this.criasTomanLeche=true; } Gato = function(name){ obj = new Mamifero(name); obj.especie = "gato" return obj; } micifu = new Gato ("Micifú") micifu
Métodos
Mamifero = function (name){ this.npatas=4; this.nombre = name; this.tienePelo=true; this.poneHuevos= false; this.criasTomanLeche=true; this.saluda = function(){ console.log("Hola soy " +this.nombre+" y soy un "+this.especie); return this } this.hazTuRuido = function(){ if(this.ruido) console.log(this.ruido+" ..."+this.ruido); } Gato = function(name){ obj = new Mamifero(name); obj.especie = "gato"; obj.ruido = "Miau" return obj; } micifu = new Gato ("Micifú") micifu.hazTuRuido();
class Mamifero { contrustor (name){ this.npatas=4; this.nombre = name; this.tienePelo=true; this.poneHuevos= false; this.criasTomanLeche=true; } saluda (){ console.log("Hola soy " +this.nombre+" y soy un"+this.especie); return this } hazTuRuido (){ if(this.ruido) console.log(this.ruido+" ..."+this.ruido); } }
Subclase (extend)
Loading…

no comments

    sign in to comment