JSOO - JavaScript Orientado a Objeto
Publicado por Emiliano Eloi Silva Barbosa 14/08/2006
[ Hits: 8.470 ]
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
Atualize suas paginas automaticamente
Capturando o nome do browser, vesão, código e plataforma do visitante
Adicionando um texto em movimento em html
IA Turbina o Desktop Linux enquanto distros renovam forças
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Linux em 2025: Segurança prática para o usuário
Desktop Linux em alta: novos apps, distros e privacidade marcam o sábado
IA chega ao desktop e impulsiona produtividade no mundo Linux
Atualizando o Fedora 42 para 43
Como saber se o seu e-mail já teve a senha vazada?
Como descobrir se a sua senha já foi vazada na internet?
\Boot sem espaço em disco (Fedora KDE Plasma 42) (2)
Programa fora de escala na tela do pc (38)
Mint Xfce não mantém a conexão no wi-fi (2)









