<button onclick="alert(AbstractTest.Attribute);">Exibe Atributo</button>
<button onclick="alert(AbstractTest.Method());">Exibe Resultado do Método</button>
<button onclick="alert(testInstantiation());">Exibe Resultado da Instanciação</button>
JavaScript
// INICIO - Apenas para evitar poluir o espaço global
(function(){
/**
* Construtor da classe (é realmente necessário?).
*/
var AbstractTest = function() {
};
/**
* Atributo com o texto de teste.
*/
AbstractTest.Attribute = "O atributo diz: Olá Planeta!";
/**
* Método que retorna o texto do teste.
* @return String com o texto de teste.
*/
AbstractTest.Method = function() {
return "O método diz: Olá Mundo!";
}
// Atribui a classe ao escopo global 'window'
window.AbstractTest = AbstractTest;
// FIM - Apenas para evitar poluir o espaço global
}());
/**
* Função de teste de instanciação.
* @return String com o texto de teste de uma instância criada.
*/
window.testInstantiation = function() {
// A dúvida é sobre a possibilidade de impedir a execução dessa linha:
var oTest = new AbstractTest();
oTest.Attribute = "O atributo na nova instância diz: Olá Brasil!";
return oTest.Attribute + " e " + AbstractTest.Attribute;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.