Skip to content

Instantly share code, notes, and snippets.

View saipraveen-a's full-sized avatar
:octocat:
Working From Home

Sai Praveen saipraveen-a

:octocat:
Working From Home
View GitHub Profile
@saipraveen-a
saipraveen-a / README.md
Last active September 19, 2020 12:23
JavaScript Understanding the Weird Parts - Function Constructors

Function Constructors are one way of creating Objects in JavaScript. The other ways are Object literal syntax and using Object.create

It was added to appease Java Developers back in the late 90's.

What happens when we write new Person()?

When the Javascript Engine sees a new Operator, it creates a new Object of type Person and then passes this Object as the this value to the Execution Context of the Person() function thats invoked. Within the context of the execution,

@saipraveen-a
saipraveen-a / README.md
Last active September 19, 2020 12:56
JavaScript Understanding the Weird Parts - Function Constructor Prototype

How is the Prototype set when an Object is created using the Function Constructor?

The process of creating an Object using the Function Constructor automatically sets the Prototype for the new Object thats created.

Every function in Javascript has some properties like NAME (optional for anonymous functions), CODE and prototype.

The prototype property of the function will be used as the prototype (proto) of any object that is created using the function constructor. In other words, jonh.proto is the same as Person.prototype

@saipraveen-a
saipraveen-a / index.js
Last active September 19, 2020 13:16
JavaScript Understanding the Weird Parts - Built-In Function Constructors
let a = new Number(3);
a;
a.toFixed(2);
Number.prototype.toFixed(2);
let b = new String('John');
b.indexOf('o');
String.prototype.indexOf('o');
@saipraveen-a
saipraveen-a / index.js
Created September 19, 2020 13:29
JavaScript Understanding the Weird Parts - Array for in
const names = ['John', 'Jane', 'Joe']
for (let key in names) {
console.log(key + ": " + names[key]); // array is an object with the key being the index
}
Array.prototype.someNewProperty = 'abc';
// now we get the new property someNewProperty in the output as well.
for (let key in names) {
@saipraveen-a
saipraveen-a / README.md
Created September 19, 2020 13:51
JavaScript Understanding the Weird Parts - Creating Objects using Object.create

Function Constructors were added for programmers coming from OO programming backgrounds.

Javascript also supports creating Objects using its own Prototypal Inheritance through the use of Object.create()

Objects dont create new Execution Context. Only a function invocation results in the Creation and Execution of new Execution Context.

Object.create is supported in newer browser versions. If we have to run our application in older browsers, we can instead use Polyfills (code that adds a feature that the engine may lack)

@saipraveen-a
saipraveen-a / index.js
Created September 19, 2020 14:03
JavaScript Understanding the Weird Parts - Classes in ES6
// classes are just syntatic sugar in Javascript. They are just objects underneath
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
greet() {
return 'Hi' + firstName;
}
@saipraveen-a
saipraveen-a / GitHub-GraphQL-Query.md
Last active October 3, 2020 04:13
GraphQL Reference Queries and Mutations

Get Repositories

``query GetRepositories { repository(name: "test-bottle-app", owner: "saipraveen-a") { name parent { name } createdAt watchers {

@saipraveen-a
saipraveen-a / index-1.html
Last active October 13, 2020 11:25
Inline CSS Basics
<html>
<head>
<title>Introduction to CSS</title>
</head>
<body>
<!--
#42f4df
#f77002
#13a351
rgb(206, 105, 72)
@saipraveen-a
saipraveen-a / style.css
Created October 13, 2020 11:58
CSS Borders
/* Snippet1 */
header {
width: 100px;
border-color: yellow;
border-width: 20px;
border-style: solid;
padding: 20px;
margin: 20px;
@saipraveen-a
saipraveen-a / main-intro.html
Created October 13, 2020 12:28
Building a Multi-Column Layout
<html>
<head>
<title>HTML & CSS</title>
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<header>
<h1>I'm learning HTML and CSS</h1>
</header>