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;
public class Main { public static void main(String[] args) { Man bob = new Man("Bob"); System.out.println(bob.name); //referenced from object, prints Bob System.out.println(Man.gender); //referenced from class name, prints Male } }
Man fred; try { fred = new Man(); } catch (Exception e) { e.printStackTrace(); } if (fred != null) { System.out.println(fred); }
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(); } }
try { Man fred = new Man(); print(fred.getName()); } catch (Exception exc) { exc.printStackTrace(); }
Man fred = null; try { fred = new Man(); } catch (Exception e) { e.printStackTrace(); } if (fred != null) { System.out.println(fred.getName()); }
var Man = function () {}; Man.prototype = new Human(); var man = new Man(); man.name = 'Matt'; console.log(man.name);
//Initialise outer-class Man man = new Man(); //initialise nested-class MAN.PUNCH punch = man.new PUNCH(); //resolve the method of your nested class punch.methodInPUNCH();
Man fred = null; try { fred = new Man(); } catch (Exception e) { System.out.println(e.printStackTrace()); } finally { //You could do some clean up. } if(fred != null) { System.out.println(fred.getName()); }
Man man = new Man(); Punch punch = man.getPunch(); punch.somePunchMethod();