var man = new Man ({name : 'qian', age : 12}); man.set({ age: 12 }); // that will trigger alert
Person pM; switch (typeOfPerson) { case "Man": { Man man = new Man(); man.setOccupation("military"); pM = man; break; } case "Student": { Teenager teenager = new Teenager(); teenager.setStdyPlace("Boston"); pM = teenager; break; } default: // You need this, otherwise pM is not definitely-assigned below throw new IllegalArgumentException("Unknown type of person: " + typeOfPerson); } pM.setName(en); pM.setType(tp);
public ForgeCommandRegistry(Furnace furnace, ShellImpl shell, AddonRegistry addonRegistry) { this.furnace = furnace; this.shell = shell; this.commandFactory = addonRegistry.getServices(CommandFactory.class).get(); this.commandControllerFactory = addonRegistry.getServices(CommandControllerFactory.class).get(); this.commandLineUtil = new CommandLineUtil(addonRegistry); ConverterFactory converterFactory = addonRegistry.getServices(ConverterFactory.class).get(); InputComponentFactory inputComponentFactory = addonRegistry.getServices(InputComponentFactory.class).get(); // Use Aesh commands Man manCommand = new Man( new ForgeManProvider(shell, commandFactory, converterFactory, inputComponentFactory, commandLineUtil)); this.aeshCommandRegistry = new AeshCommandRegistryBuilder() .command(Grep.class) .command(Less.class) .command(More.class) .command(manCommand) .create(); manCommand.setRegistry(this); }
//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"; }