JavaScript – Object defineProperty

In JavaScript, there are different ways to define properties to objects. For example, if we have a Customer class, we can define properties using the this keyword, and also Object.defineproperty: function Customer (firstname, lastname, email, phonenumber) { this.firstname = firstname, this.lastname = lastname, this.email = email, Object.defineProperty(this, “phonenumber”, { writable: true, enumerable: true, configurable: false, value: phonenumber }); } //Print out Customer var Customer00001 = new Customer(“Bob”, “Smith”, “bob@test.com”, “111-222-7777”) … Continue reading JavaScript – Object defineProperty

JavaScript Object Literals

Object literals are a way to define objects in JavaScript using comma-separated name-value pairs of properties and methods. For example, we can define a Customer object with the syntax, which contains properties and a method GetCustomer(): var Customer = { firstname: “Bob”, lastname: “Smith”, email: “bsmith@test.com”, phonenumber: “555-111-2222”, GetCustomer: function() { return this.firstname + ‘ ‘ + this.lastname + ‘ ‘ + this.email + ‘ ‘ + this.phonenumber; } } … Continue reading JavaScript Object Literals

Installing a Node Web Server using http-server

Node has several web servers available for installation, including http-server: To install, type: npm install http-server -g To start the server, type: http-server This will start the web server at the addresses: Opening a web page at this address will display the contents of the current directory: If we create a folder called webserver with one file, index.html, and browse to this directory, we see the index file is displayed: … Continue reading Installing a Node Web Server using http-server