8 nov 2008

Re: [wwwDotAle] Viejo y Querido JS hasta http://extjs.es/

Despues de unos 12 años usando Js, ha vuelto y con mas ganas.
 
Para recordar OO en js !!!!!! y usar EXT JS - http://extjs.es/ 
 

<html>         
<head><title>viejo y querido JS</title></head><body>
<script type="text/javascript" language="javascript">

// clasic class

Persona =

function(){

// private field

var nombre = null;

// public field

this.Nombre ;

this.Sexo;

this.TipoDocumento;

//public metodos

this.Ver = ver;

this.Show = ver2;

//private

function ver(){

alert(

this.Nombre);

}

//private

function ver2(obj){

alert(obj);

}

 

}

// run

var

p = new Persona();

p.Nombre =

"juan";

p.Ver();

 

// generic object dinamic

var

TSexo = new Object();

TSexo.Nombre =

"M";

// run

p.Sexo = TSexo;

p.Show(p.Sexo.Nombre);

// generic object inline

var

TDoc = {"Nombre":'' , "ID":0};

TDoc.Nombre =

"DNI";

TDoc.ID = 0;

//run

p.TipoDocumento = TDoc;

p.Show(p.TipoDocumento.Nombre);

// function inline

var

ver2fn = function(texto){

alert(texto);

}

// clase inline

var

Domicilio = {

"Calle":''

,

"Nro":0

,

"Ver" :function(){ // inline

alert(

"" + this.Calle);

}

,

"Ver2" : ver2fn //puntero

};

// run

Domicilio.Calle =

"ACA";

Domicilio.Ver();

Domicilio.Ver2(

"El numero es:" +Domicilio.Nro);

//Adding methods

Persona.prototype.changeName =

function(name) {

this.Nombre = name;

}

Persona.prototype.toString =

function()

{

return "(Nombre:" + this.Nombre + ",Sexo=" + this.Sexo.Nombre + ")";

}

// run

p.changeName(

"Otro-nombre");

p.Ver();

alert(p.toString());

//

function

superTest() {

return "superTest";

}

function

subTest() {

return "subTest";

}

// clase tipo funcion

function

superClass() {

this.supertest = superTest; //attach method superTest

}

// run

var

sClass = new superClass();

alert(sClass.supertest());

 

 

// ******** pseudo-herencia

function

superClass() {

this.supertest = superTest; //attach method superTest

}

function

subClass() {

this.inheritFrom = superClass;

this.inheritFrom();

this.subtest = subTest; //attach method subTest

this.Tipo ;

}

 

//run inherit

var newClass = new subClass();

newClass.Tipo =

"1";

alert(newClass.subtest());

// yields "subTest"

alert(newClass.supertest());

// yields "superTest"

//view class

// for(x in p) alert(""+ x + "\n\r " + typeof(p[x]) + "\n\r\n\r " + p[ x ] )

 

 

alert(

"extender funciones prototype")

// extender funciones

Function.prototype.inheritsFrom =

function( parentClassOrObject ){

if ( parentClassOrObject.constructor == Function )

{

//Normal Inheritance

this.prototype = new parentClassOrObject;

this.prototype.constructor = this;

this.prototype.parent = parentClassOrObject.prototype;

}

else

{

//Pure Virtual Inheritance

this.prototype = parentClassOrObject;

this.prototype.constructor = this;

this.prototype.parent = parentClassOrObject;

}

return this;

}

function DomicilioComercial(tel){

this.tel=tel;

this.emails=[];

}

DomicilioComercial.inheritsFrom( Domicilio );

 

//run

var

f = new DomicilioComercial( "4878844" );

f.Calle =

"San MArtin";

f.Ver();

// override

DomicilioComercial.prototype.Ver=

function(){

// alert("this.parent:" + this.parent);

//this.parent.Ver.call(this);

// var tt = this.parent.Ver.call(this);

alert(

this.Calle + "-"+ this.tel);

// return tt;

}

//run

var

f2 = new DomicilioComercial( "444444444" );

f2.Calle =

"Las Heras";

f2.Ver();

</

script>

</

body>
</
html>
 
 
 
 

 

FeedCount

analytics

 
sfrede