var calc = {
status: 'Awesome',
plus: function (a,b) {
return (
console.log(this),
console.log(a+b),
console.log(arguments),
console.log(this.status)
)
}
}
calc.plus(2,2);
/// Invocando atra ves de constructor
var Dog = function() {
var name, breed;
return console.dir(this);
}
firstDog = new Dog; //crea una instancia
firstDog.name = "Rover";
firstDog.breed = "Doberman";
secondDog = new Dog;
secondDog.name = "Fluffy";
secondDog.breed = "Poodle"
lunes, 16 de marzo de 2015
viernes, 13 de marzo de 2015
Crear objetos en javascript
var person = { //igual que arriba pero cn mayo performance
nombre : "Cesar",
apellido : "Morones",
hola : function(){
return "Hola Cesar";
}
};
nombre : "Cesar",
apellido : "Morones",
hola : function(){
return "Hola Cesar";
}
};
Clousure
Funciones clausura
Son funciones que reornan una funcion con variables de un scope externo.
function testClosure(){
var x =4; // solo es local esta variable
return x;
}
///// Es este ejemplo la funcion interior puede accesar a las variables de la funcion exterior ya que las toma como variables globales, no es necesario pasarla como parametro.
function testClosure(){
var x =4; // solo es local esta variable
function closeX(){
return x;
}
retun closeX;
}
var checkloalX = testClosure();
checkLocalX();
---> 4
function buildCoverTicketMaker( transport )
{
return function (name) {
alert ("Here is your transportation ticket via the " + transport + ".\n" + "wlecome to the Cold Closures Cove" + name + "!");
}
}
var getSubmarineTicket = buildCoverTicketMaker( "Submarine");
var getBatleShipTicket = buildCoverTicketMaker( "Balteship");
var getGiantTicket = buildCoverGiantMaker( "Giant Seagull");
getSubmarineTicket ("cesar");
Son funciones que reornan una funcion con variables de un scope externo.
function testClosure(){
var x =4; // solo es local esta variable
return x;
}
///// Es este ejemplo la funcion interior puede accesar a las variables de la funcion exterior ya que las toma como variables globales, no es necesario pasarla como parametro.
function testClosure(){
var x =4; // solo es local esta variable
function closeX(){
return x;
}
retun closeX;
}
var checkloalX = testClosure();
checkLocalX();
---> 4
function buildCoverTicketMaker( transport )
{
return function (name) {
alert ("Here is your transportation ticket via the " + transport + ".\n" + "wlecome to the Cold Closures Cove" + name + "!");
}
}
var getSubmarineTicket = buildCoverTicketMaker( "Submarine");
var getBatleShipTicket = buildCoverTicketMaker( "Balteship");
var getGiantTicket = buildCoverGiantMaker( "Giant Seagull");
getSubmarineTicket ("cesar");
Invocar funciones inmediatamente
var parkRides = [["Birch Bumpers",40],["Pines Plunge",40],["Cedar Coaster",40],["Ferris wjhell of firs",40]];
var fastPassQueue = ["Pines Plunge", "Birch Bumpers", "Pines Plunge"];
var watsRide = "Pines Plunge";
buildTicket(parkRides, fastPassQueue, watsRide )();
function buildTicket( allRides, passRides, pick){
if(passRides[0] == pick){
var pass = passRide.shift();
return function(){
alert ("Quick! You've got a Fast Pass to " + pass + "!");
};
} else {
for( var i = 0; i< allRides.length; i++){
if(allrides[i][0]) ==pick ){
resturn function(){
alert("A ticket is printing for " + oick + "1\n" + "Your wait time is about " + allRides[i][1]"+ minutes.");
};
}
}
}
})
}
var fastPassQueue = ["Pines Plunge", "Birch Bumpers", "Pines Plunge"];
var watsRide = "Pines Plunge";
buildTicket(parkRides, fastPassQueue, watsRide )();
function buildTicket( allRides, passRides, pick){
if(passRides[0] == pick){
var pass = passRide.shift();
return function(){
alert ("Quick! You've got a Fast Pass to " + pass + "!");
};
} else {
for( var i = 0; i< allRides.length; i++){
if(allrides[i][0]) ==pick ){
resturn function(){
alert("A ticket is printing for " + oick + "1\n" + "Your wait time is about " + allRides[i][1]"+ minutes.");
};
}
}
}
})
}
Funciones
var diff = function diffOfSqueares(a, b){ // En este caso el nombre de la funcion es opcional
return a*a-b*b;
};
var diff = function (a, b){ // esta hace lo mismo no es necesario el nombre
return a*a-b*b;
};
diff(9,5);
//funciones que reciben funciones como parametros
var greeting = function (){
alert ("Gracias por tu visita\n" + "hola mundo");
}
function closeTerminal(mensaje ){
mesage();
}
closeTerminal ( greeting );
var numbers = [12, 4, 3 , 9 , 8 , 6 , 10 ,1];
var results = number.map( function (arrayCell){
return arrayCell * 2;
}
);
return a*a-b*b;
};
var diff = function (a, b){ // esta hace lo mismo no es necesario el nombre
return a*a-b*b;
};
diff(9,5);
//funciones que reciben funciones como parametros
var greeting = function (){
alert ("Gracias por tu visita\n" + "hola mundo");
}
function closeTerminal(mensaje ){
mesage();
}
closeTerminal ( greeting );
var numbers = [12, 4, 3 , 9 , 8 , 6 , 10 ,1];
var results = number.map( function (arrayCell){
return arrayCell * 2;
}
);
jueves, 12 de marzo de 2015
Validar radiobuttons
<SCRIPT LANGUAGE="javascript">
<!--
<!--
var valor = 0;
function fullName(){
var form =document.forms[1]
for (var i =0; i<form.boton.length; i++){
if (form.boton[i].checked==false){
valor++;
}
}
if (valor != form.boton.length) {
alert(document.form.boton.value)
document.form.submit();
}
else {
alert("Es necesario que seleccione un registro!!!!")
valor = 0
}
}
//-->
</SCRIPT>
<!--
<!--
var valor = 0;
function fullName(){
var form =document.forms[1]
for (var i =0; i<form.boton.length; i++){
if (form.boton[i].checked==false){
valor++;
}
}
if (valor != form.boton.length) {
alert(document.form.boton.value)
document.form.submit();
}
else {
alert("Es necesario que seleccione un registro!!!!")
valor = 0
}
}
//-->
</SCRIPT>
viernes, 6 de marzo de 2015
Levantar un servidor en Python
python -m SimpleHTTPServer 3333
y con eso se levanta un servidor de la parpeta en donde estemos ubicados.
y con eso se levanta un servidor de la parpeta en donde estemos ubicados.
Suscribirse a:
Entradas (Atom)