<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How Do I: Create and Use Classes in JavaScript?</title><link>http://www.asp.net</link><pubDate>Mon, 30 Aug 2010 10:36:20 GMT</pubDate><generator>umbraco</generator><description>Comments for How Do I: Create and Use Classes in JavaScript?</description><language>en</language><atom:link href="http://www.asp.net/rss/comments/33533" rel="self" type="application/rss+xml" /><item><title>Comment Posted by Snakiej</title><link>http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-and-use-classes-in-javascript</link><pubDate>Sat, 09 Jan 2010 11:06:10 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006387</guid><description><![CDATA[ <p>I wouldn&#39;t recommend putting your public functions like that in the constructor, since it would define the function for each of your created objects.</p><p></p><p>I would prefer using the Customer.prototype. ... way, since this creates a prototype, and every customer object than refers to that prototype. While your practice isn&#39;t a problem in simple, small websites, you can get memory problems if you use this too much.</p><p></p><p>But apart from that, great introduction, cheers! </p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/Snakiej.jpg?forceidenticon=false&amp;dt=635050468200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by dsklavenitis</title><link>http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-and-use-classes-in-javascript</link><pubDate>Tue, 12 Jan 2010 12:16:33 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006388</guid><description><![CDATA[ <p>Thank you Chris. Very Usefull.</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/dsklavenitis.jpg?forceidenticon=false&amp;dt=635050468200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by itanex</title><link>http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-and-use-classes-in-javascript</link><pubDate>Tue, 12 Jan 2010 18:01:50 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006389</guid><description><![CDATA[ <p>Well done introduction to javascript user objects(classes), introduces access priviledge levels (private and public) and dot syntax access levels for objects. When I interview people and when speaking about javascript, memory management and good javascript coding practices are questions that people fail every time. Unlike C# or VB javascript is purely interpreted and is rather slow in comparison so the more objects and methods you have running around the slower the user experience will be. Managing memory should always be a top priority. Good coding practices in JS if followed, actually present the solution for memory management.</p><p></p><p>[Coding oversight]</p><p>At the begining you point out the difference between:</p><p></p><p>alert(custFunc);</p><p>  and</p><p>alert(custObj);</p><p></p><p>But you didn&#39;t point out that custFunc === custObj() or why custFunc != custObj. It would be good for javascript beginners to know why. The difference is that one is a string object and the other is the customer object</p><p></p><p>[Poor Memory Management]</p><p>You demonstrate a bad practice in javascript and make an incorrect assumption about internal/external methods. You declared that:</p><p></p><p>function myFunct(){</p><p>}</p><p></p><p>was equivelant to </p><p></p><p>var myObj = function(){</p><p>   this.myEIntFunct = MyFunct(){</p><p>   }</p><p>}</p><p></p><p>This is incorrect. MyFunct exists in the global Dom space and then you assign a varible object inside the class object. This functionality is now in two places in Dom space. To prevent this duplication you utilize the prototype method which is built into every object.</p><p></p><p>myObj.prototype.myEIntFunct = MyFunct;</p><p></p><p>Now the only location that MyFunct method exists in is at the global DOM space. While this does not change the output, it does prevent exessive memory use, and keeps the method available to all instances of the class object.</p><p></p><p>Though this applies for objects that will be created in mass volume. A more common approach to creating internal methods and properties you did outline well. Another mistake that is made and is included in your code is the missing semicolon at the end of internal method declarations.</p><p></p><p>var MyObj = function()</p><p>{</p><p>  this.MyPubInt = 1;</p><p>  var MyPriInt = 3;</p><p></p><p>  this.MyPubMeth = function(){</p><p>  }; //semicolon ends an internal function declaration</p><p>  var MyPriMeth = function(){</p><p>  }; //semicolon ends an internal function declaration</p><p>  function MyOtherPriMeth(){</p><p>  }  //Acceptable, </p><p>     //It is recommended that you use the previous delaration style</p><p>}</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/itanex.jpg?forceidenticon=false&amp;dt=635050468200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by itanex</title><link>http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-and-use-classes-in-javascript</link><pubDate>Tue, 12 Jan 2010 18:15:21 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006390</guid><description><![CDATA[ <p>Good point Snakiej. Also if you assign a method created in Global Dom Space to a class you then have 2 copies of it.</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/itanex.jpg?forceidenticon=false&amp;dt=635050468200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by abelanet</title><link>http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-and-use-classes-in-javascript</link><pubDate>Tue, 19 Jan 2010 20:13:14 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-000000006391</guid><description><![CDATA[ <p>Thanks for this interesting video</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/abelanet.jpg?forceidenticon=false&amp;dt=635050468200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by elgzza</title><link>http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-and-use-classes-in-javascript</link><pubDate>Mon, 30 Aug 2010 10:36:20 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000010047</guid><description><![CDATA[ <p>i like your  teachimg</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/elgzza.jpg?forceidenticon=false&amp;dt=635050468200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item></channel></rss>