<?xml version="1.0" encoding="UTF-8"?><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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C++ classes &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/c-classes/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Quick Look at JavaScript Objects</title>
		<link>/2010/08/11/quick-look-at-javascript-objects/</link>
		<comments>/2010/08/11/quick-look-at-javascript-objects/#respond</comments>
		<pubDate>Wed, 11 Aug 2010 17:38:55 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[C++ classes]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Set-builder notation]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/?p=1900</guid>
		<description><![CDATA[JavaScript Objects As you may know there are different notations of objects in JavaScript, and there are slight differences. However here I&#8217;m gonna achieve the same thing with different notations. The first one is the object notation in JavaScript known mostly from JSON. There you&#8217;ve to construct a key/value pairs, divided by a colon: var &#8230; <a href="/2010/08/11/quick-look-at-javascript-objects/" class="more-link">Continue reading <span class="screen-reader-text">Quick Look at JavaScript Objects</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2009/07/08/javascript-closures-in-brief/" rel="bookmark" title="JavaScript closures in brief">JavaScript closures in brief </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript Objects</h2>
<p>As you may know there are different notations of objects in JavaScript, and there are slight differences. However here I&#8217;m gonna achieve the same thing with different notations. The first one is the object notation in JavaScript known mostly from JSON. There you&#8217;ve to construct a key/value pairs, divided by a colon:</p>
<pre lang="javascript">
var class1 = {
    a : 0,
    func1 : function() {
        console.log(class1.a);
    },
    func2 : function(a) {
        this.a = a;
    }
}
class1.func2(3);
</pre>
<p>Here we have two functions &#8211; func1 and func2 and one member variable. Func2 is setting up the member variable, it&#8217;s something like a setter in some languages like Java and PHP, and the func1 is printing the value of that variable via console.log(). Note that in the body of func1() the variable &#8220;a&#8221; is accessed with the class name: class1.a. Here the notation can be changed to this.a, which will result in the same thing.</p>
<pre lang="javascript">
...
console.log(this.a);
...
</pre>
<h2>Notation #2</h2>
<p>While in the notation I&#8217;ve just used is not possible to have two different instances from the same class, in the next example this is possible. In JavaScript the objects are even the functions, and you can access the function&#8217;s private variables with the dot notation.</p>
<pre lang="javascript">
var class2 = function() {
    this.a = 0;
    this.func1 = function() {
        console.log(this.a);
    }

    this.func2 = function(a) {
        this.a = a;
    }
}
</pre>
<p>To use this object you&#8217;ve to use the &#8220;new&#8221; operator.</p>
<pre lang="javascript">
var c = new class2();
c.func2(4);
</pre>
<p>This helps you create more than one instance of the same class.</p>
<pre lang="javascript">
var c = new class2();
var d = new class2();
c.func2(3);
d.func2(4);
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2009/07/08/javascript-closures-in-brief/" rel="bookmark" title="JavaScript closures in brief">JavaScript closures in brief </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/11/quick-look-at-javascript-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
