var man = new Man ({name : 'qian', age : 12}); man.set({ age: 12 }); // that will trigger alert
//Object will be created with invalid attribute 'age' var man = new Man({name : 'qian', age : 12}); console.log(man) // Returns an object with invalid attributes // But we'll use only valid objects. // Also we'll get the error message in alert, if validation fails. if(man.isValid()){ alert( man.get('name') ); } var man = new Man({name : 'qian', age : 19}); if(man.isValid()){ alert( man.get('name') ); }
Man Fred = null; try { Fred = new Man(); } catch (exception e) { print e } finally { //You could do some clean up. } if(Fred != null) { print Fred.getName(); }
function Person(a, b) { this.a = a; this.b = b; } function Man() {} Man.prototype = new Person("val1", "val2"); var m = new Man(); console.log(m.a);
function Man(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } Man.prototype.getName = function () { return this.firstName + " " + this.lastName; }; var joe = new Man("Joe", "Bloggs"); console.log(joe.getName()); // "Joe Bloggs" Man.prototype.introduction = function() { return "Hi there, I'm " + this.getName(); }; console.log(joe.introduction()); // "Hi there, I'm Joe Bloggs"
Man maxAge = new Man(0); boolean isAmaxFoud = false; for(Man man : list) { if(man.age > maxAge.age) { maxAge = man; isAmaxFound = true; } } if(!isAmaxFound) // <<--- all age are equal print "Equals "+list.get(0) else print maxAge
Man Fred = null; Try { Fred = new Man(); } catch (exception e) { Print e } If(Fred != null) { Print Fred.getName (); }
Man maxAge = new Man(0); for(Man man : list) { if(man.age > maxAge.age) { maxAge = man; } }
// set this.Man == window.Man to Peter function Man() { this.Man = "Peter"; } // create an constructor for each object Man Man.prototype = { constructor: this.Man } // create an object var man = new Man(); // call his property which was set in the constructor of the prototype man.Man;
function Person() {} Person.prototype.walk = function() { return 'I can walk' } Person.prototype.swim = function() { return 'I can swim' } function Man() {} Man.prototype = Object.create(Person.prototype); var m = new Man(); // in this way Person gets every method that is assigned onto Person.prototype // so swim method is available and can be used by objects of type Man now: m.swim(); console.log('is true: ', m instanceof Person); console.log('parent constructor is Person: ', m.__proto__.__proto__.constructor);
function Man () { this.standingID = ""; this.leftID = []; this.rightID = []; }; var tmp = new Man(); tmp.standingID = "C:\\**"; tmp.leftID.push ("1"); var tmpD = tmp.standingID;
MAN man = new Man(); PUNCH punch = man.getPunch(); punch.yourMethodInPunch();
static void updMan(Man man) { man = new Man(); man.name = "Another Man"; }
Man man = new Man(); Human human = man //Legal. Man man2 = (Man) humain; //Legal Woman human = (Woman) humain; //Error, Java can't cast the humain to Woman, because its declared originaly as Man.
//Object will be created without any passed attributes var man = new Man({name : 'qian', age : 12}, {validate:true}); console.log(man) //Object will be without passed attributes /* man.isValid() returns 'true' throw we passed invalid attrs. We won't see any error alert message, because Backbone created empty object */ /* Doesn't work */ if(man.isValid()){ alert( man.get('name') ); //undefined } /* Works */ // Created model had invalid attrs, so validationError won't be empty. // If all attrs are valid, validationError will be empty if(!man.validationError){ alert( man.get('name') ); }
var man = new Man({name : 'qian', age : 12}, {validate : true});
public abstract class CommonSuperClass { public abstract One getOne(); public abstract Two getTwo(); } public class A extends CommonSuperClass { @Override public One getOne() { return new Bla(); } @Override public Two getTwo() { return new Coda(); } } public class B extends CommonSuperClass { @Override public One getOne() { return new Cop(); } @Override public Two getTwo() { return new Man(); } }