JSOO - JavaScript Orientado a Objeto
Publicado por Emiliano Eloi Silva Barbosa 14/08/2006
[ Hits: 8.248 ]
Homepage: http://emilianoeloi.com.br
Um exemplo de um JavaScript orientado a objetos
<HTML> <HEAD> <TITLE>Classe Ítem</TITLE> <SCRIPT> /** * @description Classe Item. Manipulação de itens * * @package Teste * @since 2006-04-27 * @author Emiliano ESB <emiliano@portinfo.com.br> * @access public */ function Item(id, description, quantity, price) { this.id = id; this.description = description; if(quantity >=0) this.quantity = quantity; else this.quantity = 0; this.unit_price = price; this.discount; /** * Acessor getAdjustedTotal */ this.getAdjustedTotal = function() { total = this.unit_price * this.quantity total_discount = total * this.discount adjusted_total = total - total_discount return adjusted_total } /** * Mutante setDiscount */ this.setDiscount = function(discount) { if(discount <= 1) this.discount = discount else this.discount = 0 } /** * Acessor getDiscount */ this.getDiscount = function() { return discount } /** * Acessor getQuantity */ this.getQuantity = function() { return quantity } /** * Mutante setQuantity */ this.setQuantity = function(quantity) { if(quantity>=0) quantity = quantity } /** * Acessor getProductID */ this.getProductID = function() { return id } /** * Acessor getDescription */ this.getDescription = function() { return description } } var objMilk = new Item('diary-011','1 Gallon Milk',2,2.50) objMilk.setDiscount(0.15) milk_price = objMilk.getAdjustedTotal(); SAIDA = "Obrigado pela sua compra\n" SAIDA += "Por favor, volte!\n" SAIDA += objMilk.getDescription() + "\t" + milk_price + "\n" SAIDA += "Preço total \t" + milk_price alert(SAIDA) </SCRIPT> </HEAD> <BODY> </BODY> </HTML>
Bloqueando o teclado do visitante
"Apontar"-links para um iframe
Script de um programa de HTML em java
Atenção a quem posta conteúdo de dicas, scripts e tal (6)
Como Configurar um Túnel SSH Reverso para Acessar Sua Máquina Local a Partir de uma Máquina Remota
Configuração para desligamento automatizado de Computadores em um Ambiente Comercial
O mínimo que você precisa saber sobre o terminal (parte 2)
O mínimo que você precisa saber sobre o terminal (parte 1)
Como iniciar uma máquina virtual do VirtualBox automaticamente no boot do LUbuntu 18 LTS
Mudar o gerenciador de login (GDM para SDDM e vice-versa) - parte 2
Como deixar as abas do Firefox mais fininhas
Mudar o gerenciador de login (GDM para SDDM)
"Tentando" fazer com que programas rodem no Wayland e no X11
Porblema com MergeList [RESOLVIDO] (10)
Melhor hospedagem em nuvem para projetos Laravel com baixo custo? [RES... (7)
Como baixar os drivers de áudio no linux mint? (7)
Como posso localizar o arquivo HTML da página inicial do GLPI dentro d... (2)
[Python] Automação de scan de vulnerabilidades
[Python] Script para analise de superficie de ataque
[Shell Script] Novo script para redimensionar, rotacionar, converter e espelhar arquivos de imagem
[Shell Script] Iniciador de DOOM (DSDA-DOOM, Doom Retro ou Woof!)
[Shell Script] Script para adicionar bordas às imagens de uma pasta