secret
Last active

  • Download Gist
BuildConstraint.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
var XMLFormBuilder = XMLFormBuilder || {} ;
 
XMLFormBuilder.BuilderConstraint = (function()
{
function BuilderConstraint(){
this.constraints = new Array();
}
BuilderConstraint.prototype.add=function(constraint){
this.constraints.push( constraint );
}
BuilderConstraint.prototype.applyContraints=function()
{
var out = "";
/*
this.constraints.forEach(function(object){
out+=object.handle();
});*/
for(var index in this.constraints ){
var constraint = this.constraints[index];
/*Aquí se me presenta un error, ya que no me
*reconoce el método handle de los objetos tipo Constraint
*que agrege al array
*/
out+= constraint.handle();
}
return out;
}
return BuilderConstraint;
})();
Constraint.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/**
*Clase padre
*/
 
var XMLFormBuilder = XMLFormBuilder || {} ;
 
XMLFormBuilder.Constraint= (function()
{
function Constraint( value, succesor, type ){
this.value = value || "UNDEFINED";
this.succesor = succesor || null;
this.type = type || "UNDEFINED";
this.noTopic = "UNDEFINED";
};
Constraint.prototype.handle = function()
{
if(typeof null != this.succesor ){
{
return this.succesor.handle();
}
};
Constraint.prototype.has = function()
{
return this.type != this.noTopic;
};
return Constraint;
})(); //<--Aquí se genera un error no entiendo ¿Por qué? (con o sin punto y coma)
StringConstraint.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/**Clase Hijo*/
var XMLFormBuilder = XMLFormBuilder || {} ;
 
XMLFormBuilder.StringConstraint=(function(_super)
{
 
function StringConstraint( value, succesor )
{
this.value = value || "UNDEFINED";
this.succesor = succesor || null;
_super.call( this.value, this.succesor, "cadena" );
/**Aquí hay un error, porque no se como llamar correctamente al contructor
* de la clase padre o como lo sugiere el error que _super no esta definido .
* Cannot call method 'call' of undefined;
*/
};
/*Aquí se genera un error si activo la sobreescritura del prototipo:
Uncaught SyntaxError: Unexpected token ) /entidad/js/Constraint.js:28
Uncaught TypeError: undefined is not a function StringConstraint.js:16
Uncaught TypeError: undefined is not a function
StringConstraint.prototype = new _super;*/
StringConstraint.prototype.handle=function()
{
if(this.has())
return "type='text'";
else
return _super.handle();
};
StringConstraint.prototype.has = function()
{
return this.type === "cadena";
}
return StringConstraint;
})(XMLFormBuilder.Constraint);
app.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
$(function()
{
var value = "cadena";
var stringConstraint = new XMLFormBuilder.StringConstraint(value);
var builderConstraint = new XMLFormBuilder.BuilderConstraint();
builderConstraint.add(stringConstraint);
console.log( builderConstraint.applyContraints() );
 
});
/**
* En resumen estos son los errores que me genera:
*Uncaught SyntaxError: Unexpected token ) /entidad/js/Constraint.js:29
*Uncaught TypeError: Cannot call method 'call' of undefined
*/

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.