Clase javascript


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function operaciones_globales(valor) {
  2.  
  3. //Es necesario utilizar la palabra reservada this esto para identificar
  4. //que la variable pertenece a una instancia determinada.
  5. this.valor=new Number(valor);
  6. //creamos una variable que tendrá como valor el resultado de un método (validacion2)
  7. this.validacion2=validacion2;
  8. }
  9.  
  10. //Método
  11. function validacion2(){
  12. //this.valor es la variable que se creo a la instancia del objeto.
  13. entero = this.valor / 6;
  14. residuo = this.valor % 6 ;
  15. if(residuo==0){ return this.valor;}
  16. else{
  17. alert("Este no es un multiplo de 6 se convirtio");
  18. while(residuo!=0){
  19. this.valor--;
  20. residuo = this.valor % 6 ;
  21. }
  22. return this.valor;
  23. }
  24. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.