Path: csiph.com!aioe.org!.POSTED!not-for-mail From: g4b0 Newsgroups: it.comp.lang.javascript Subject: Re: Approfondire Javascript Date: Mon, 25 Jan 2016 13:54:48 +0100 Organization: Aioe.org NNTP Server Lines: 38 Message-ID: <56A61B18.9050704@gmail.com> References: <2016011514270221669@mynewsgate.net> <56991466.7030502@gmail.com> <2016011516424221669@mynewsgate.net> <56A0F909.8060508@gmail.com> <7fd10a00-f714-4637-9333-3f75b62bae92@googlegroups.com> NNTP-Posting-Host: bsUl238PqlffZge33dtVzQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com it.comp.lang.javascript:7985 On 21/01/2016 21:18, 4ndre4 wrote: > Il metodo migliore per costruire oggetti e` usare il constructor/prototype pattern: > > function Dog(name, breed) { > this.name = name; > this.breed = breed; > } > > Dog.prototype.bark = function() { > alert(this.name + ': arf! arf!'); > }; > > Dog.prototype.howl = function() { > alert(this.name + ': ouuuuuuu!') > } > > var dog1 = new Dog('Fido', 'German Shepherd'); > var dog2 = new Dog('Pluto', 'Bloodhound'); > > dog1.bark(); > dog2.howl(); Avevo letto da qualche parte che dal punto di vista delle performance passare attraverso il prototype è meno performante che dichiarare i metodi direttamente, ma forse era un articolo datato... Però firefox che nella console mi segnala questo warning: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create In realtà non indica il codice a cui si riferisce, per cui forse sono io che faccio confusione. Oppure no? -- g4b0, linux user n. 369000 http://brosulo.net