Acerca de Linux, BSD y notas personales

Archives for javaScript category

Navigator Object

  • Determine details of the user browser
  • appName – browser application name
  • appVersion – string containing version details
  • cookieEnabled – boolean value
  • mimeTypes – array of known types of files
  • plugins – array of plug-in application
  • platform – operating system

http://www.devguru.com/technologies/javascript/11226.asp

 

Creating and extending objects

Why develop objects?

  • Data hiding
  • Code elegance
  • Code reuse
  • Script stability

Steps for developing custom objects

  • Design properties and methods
  • Create constructor functions
  • Develop methods
  • Bind methods to objects

 

Anatomy of an object

  • information that describes the object
  • functions that change the state of the object

 

Duality of the object

variable -> function
property (information about the object)-> method (what the object can do)
attribute->behaviour
description->action
adjetive->verb

Encapsulation

  • Binding data and functions
  • Provides robust and secure set of elements
  • simple interface hide details
  • class an object prototype
  • Object instantaion with instructions

Inheritance

  • enables the development of a new object
  • … by extending and existing one (base)
  • Eases development while facilitating flixibility

Polymorphism

  • Associating different but related classes
  • using commond funcionts

 

String Method

 document.write(”<h1>String Methods</h1>”);

   var sample_string = “AaBbCcDdEeFfGg”;

   document.write(”<br>Orignal String: ” + sample_string);

   document.write(”<h2>Formatting</h2>”);

   document.write(”<br>toLowerCase: ” + sample_string.toLowerCase());

document.write(”<br>toUpperCase: ” + sample_string.toUpperCase());

document.write(”<br>bold: ” + sample_string.bold());

document.write(”<br>italics: ” + sample_string.italics());

document.write(”<br>strike: ” + sample_string.strike());

document.write(”<br>big: ” + sample_string.big());

document.write(”<br>small: ” + sample_string.small());

document.write(”<br>sup: ” + sample_string.sup());

document.write(”<br>sub: ” + sample_string.sub());

document.write(”<br>fixed: ” + sample_string.fixed());

document.write(”<br>fontcolor(red): ” + sample_string.fontcolor(”#FF0000″));

document.write(”<br>fontsize(-3):” + sample_string.fontsize(”-3″));

document.write(”<br>fixed: ” + sample_string.fontsize(”-3″));

 

   document.write(”<h2>Processing</h2>”);

 

document.write(”<br>substr(2, 2): ” + sample_string.substr(2, 2));

document.write(”<br>substring(2, 4): ” + sample_string.substring(2, 4));

document.write(”<br>concat(\”XxYxZz\”): ” + sample_string.concat(”XxYxZz”));

document.write(”<br>charAt(0): ” + sample_string.charAt(0));

document.write(”<br>charCodeAt(0): ” + sample_string.charCodeAt(0));

document.write(”<br>indexOf: ” + sample_string.indexOf(”A”));

document.write(”<br>search(\”Cc\”): ” + sample_string.search(”Cc”));

document.write(”<br>replace(\”Cc\”, \”Zz\”): ” + sample_string.replace(”Cc”, “Zz”));

Simple Date

 tempDate = new Date();
 document.write(”Fecha: ” + tempDate.toLocaleString());
 
 otraFecha = new Date(2007, 04, 11, 10, 52, 30);
 
 document.write(”<br> Otra Fecha:” + otraFecha + “<br>”);
 
 document.write(”Date: ” + otraFecha.getDate() +”<br>”);
 document.write(”Month: ” + otraFecha.getMonth() +”<br>”);
 document.write(”Year: ” + otraFecha.getYear() +”<br>”);
 document.write(”Locale String: ” + otraFecha.toLocaleString() +”<br”);
 

funciones functions javaScript

 /* FUNCTIONS */
 
 function hola_usuario()
 {
  document.write(”Hola que tal <br>”) 
 }
 
 function raiz(x)
 {
 
  return x * x ;
 
 }
 
 
 hola_usuario();
   
 numero=prompt(”Ingresa un numero”, 0);
 document.write(raiz(numero));

DO WHILE

 /* DO WHILE */
 
 var requested_month=0;
 var MonthArray=
 [
 "",
 "Enero",
 "Febrero",
 "Marzo",
 "Abril",
 "Mayo",
 "Junio",
 "Julio",
 "Agosto",
 "Septiembre",
 "Octubre",
 "Noviembre",
 "Diciembre"
 
 ]
 
 document.write(”Ingresa un número del 1 al 12: <br>”);
 
 do
 {
 
 requested_month=prompt(”Ingresa un numero del 1 al 12 o 0 para salir”, 0);
  if ( requested_month <= 12 )
   {
    document.write(MonthArray[requested_month] + “<BR>”);
   }
 
 }while (requested_month != 0)
 

for loops

 /* FOR LOOPS */
 
 var hora;
 var ampm;
 
 for ( hora=1; hora<=24; hora++)
 {
  if (hora < 12) { ampm = “am” }
  if (hora > 12) { ampm = “pm” }
  
  if (hora < 13 )
  {
   document.write(hora + ampm)
  }
   else
  {
    
   document.write((hora-12) + ampm)
  
  }
  
  document.write(”<br>”);
 
 
 }
 

Switch Case

 var clave_admin=”ice”;
 var clave_dev=”snow”;
 var clave_user=”water”;
 
 var login=prompt(”Ingresa la clave porfavor: “, ” “);
 
  switch (login) {
  
  case “ice”:
   alert(”Hola Administrador”);
   break
  case “snow”:
   alert(”Hola Desarrollador”);
   break
  case “water”:
   alert(”Bienvenido Usuario”);
   break
   
   default:
   alert(”Clave incorrecta”);
   break
    
  }

Variables

var number_1 = 999.9;
var number_2 = 0.1;
var sum = number_1 + number_2;
document.write(sum);

/* Strings */
var string_1 = “Buenas Tardes<br>”;
var string_2 = “¿Como estas?<br>”;
var saludo = string_1 + string_2;
document.write(saludo);

/* Arrays */

ciudades = [ "merida", "yucatan", "mexico<br>" ];
document.write(ciudades);

var reservacion_vuelo = {aerolinea:”Mexicana”,numero:342,asiento:”34f”};
document.write(reservacion_vuelo.numero);

var clave = “romeo”;
var verifica=prompt(”Ingresa la clave para continuar”,” “);
if (verifica != clave)
{
alert(”No es Bitch”);
}
else
{
alert(”Bingo!”);
}
javasample01.htm