Create JavaScript Objects
by Wentz Wu
HTML
<h1><a href="https://www.w3schools.com/js/js_object_definition.asp" target="_blank">JavaScript Objects</a></h1>
<p>In JavaScript, almost "everything" is an object.</p>
<ul>
<li>Booleans can be objects (if defined with the <strong>new</strong> keyword)</li>
<li>Numbers can be objects (if defined with the <strong>new</strong> keyword)</li>
<li>Strings can be objects (if defined with the <strong>new</strong> keyword)</li>
<li>Dates are always objects</li>
<li>Maths are always objects</li>
<li>Regular expressions are always objects</li>
<li>Arrays are always objects</li>
<li>Functions are always objects</li>
<li>Objects are always objects</li>
</ul>
<div id="result">
</div>
<ol>
<li><a href="" target="_blank">What You Should Already Know about JavaScript Scope</a>
<cite>Lexical scoping is nice, because we can easily figure out what the value of a variable will be by looking at the code</cite>
<cite>Merely accessing a variable outside of the immediate scope (no return statement is necessary) will create something called a closure.</cite>
</li>
</ol>
CSS
cite:before {
content: ' ';
display: block;
}
JavaScript
var console = document.getElementById("result");
console.log = function(msg) {
console.innerText += (msg + "\n");
};
f1();
function f1() {
var a = "a"; //a is NOT an object
var b = new String("b"); // b is an object
var c = {};
var d = new Object();
var p = new Persion("Jack");
a.x = "";
b.x = "";
c.x = "";
d.x = "";
f2(a, b, c, d);
console.log("a.x = " + a.x); //undefined, a is NOT an object
console.log("b.x = " + b.x); //x, b is an object
console.log("c.x = " + c.x); //x, c is an object
console.log("d.x = " + d.x); //x, d is an object
console.log("p.FullName = " + p.FullName);
}
function f2(a, b, c, d) {
a.x = "yes";
b.x = "yes";
c.x = "yes";
d.x = "yes";
}
function Persion(fullName) {
this.FullName = fullName;
}