Skip to content

Instantly share code, notes, and snippets.

@gokulkrishh
Last active August 8, 2016 05:46
Show Gist options
  • Save gokulkrishh/e0bab401e48e0e0937659d3b3380c36d to your computer and use it in GitHub Desktop.
Save gokulkrishh/e0bab401e48e0e0937659d3b3380c36d to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
</body>
</html>
//Javascript concepts
//Hoisting
// function funz() {
// console.log(foo);
// var foo = "hello";
// console.log(foo);
// }
//Closure
// function parent() {
// var foo = "hello";
// function child() {
// console.log(foo + " world");
// }
// child();
// }
//this
function funzThis(name,age) {
console.log(this); //window
this.name = name;
console.log(this.age); //obj
}
funzThis();
var obj = { name: "Ephicacy", age: 25 };
funzThis.call(obj, "ephicacy1", 30);
//myFunz("hello");
//call, apply
//Reference
// var obj = { foo: 1 };
// var myObj = obj;
// myObj.foo = 2;
// console.log(obj); // { foo: 2 }
//Inheritance
// function parent() {
// this.name = "parent";
// }
// parent.prototype.print = function() {
// console.log(this.name);
// }
// function child() {
// this.name = "child";
// }
// child.prototype = Object.create(parent.prototype);
// var childIns = new child();
// console.log(childIns);
//Loop
// var obj = { name : "Gokul", age : 25}
// for (var i in obj) {
// console.log(obj[i]); //print gokul, 25
// }
// //But using for of we sould be careful, because for of iterates till prototype chain
// // So use hasOwnproperty(); to avoid it
//ES6
//Fat Arrow
// (() => { alert("From fat arrow") });
//Maps this automatically for us
//No need for .bind();
//Object
// var options = {name : 'Bar'};
// var obj = {
// // Shorthand for options: options
// options,
// // Shorthand for Methods
// printName() {
// console.log("printName");
// }
// };
// obj.printName(); //printName
//Parameters
// function funz(a, b = 5) {
// console.log(a + b); //print 6
// }
// // Equivalent to: b === 5 if b is undefined or not passed
// funz(1);
//Variables = let, const
// var obj = {
// name: 'Gokul',
// age: 21,
// car: 'Swift'
// };
// //let is block level variable here
// for (let i in obj) {
// console.log(i); //print name age car
// }
// console.log(i); //i is not defined
//Const
// const bar = 'Hello';
// console.log(bar); //print Hello
// bar = 'World'; //"bar" is read-only
//Template string
// var name = 'Foo';
// var multiLineString = `Hello ${name}
// asdasdas`;
// console.log(multiLineString);
//Iterators
// for (let i of [1, 2, 3]) {
// console.log(i); //1 2 3
// }
//Promise
//Creating a promise object
//sequential asynchronous operations in javascript
// var promise = new Promise(function(resolve, reject) {
// //Making an ajax call
// $.ajax({
// url : 'https://api.github.com/users/gokulkrishh',
// method: 'get'
// })
// .success(function (response) {
// resolve(response); //Return response
// })
// .error(function (error) {
// reject(error); //Return error
// });
// });
// //Then callback to listen to resolve or rejected state
// promise.then(function (response) {
// console.log('Success -->', response);
// },
// //Reject callback
// function (error) {
// console.log('Error -->', error);
// })
// //To handle error
// .catch(function (e) {
// console.log(e);
// });
//Inheritance
// class Parent {
// print() {
// console.log('I am a class');
// }
// }
// Parent(); //Type error: Cannot call a class as a function
// var myParent = new Parent(); //Use `new` keyword to use class as construtor
// new Parent().print(); //print I am a class
//Modules
//Export
// export function printName(msg) {
// console.log('My name is ' + msg);
// }
//export var myDefaultName = 'Foo';
//Import
// import {myDefaultName, printName as printMyName} from './myFunz';
// printMyName('Bar'); //print My name is Bar
// console.log(myDefaultName); //print Foo
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"babel-runtime": "6.9.2"
}
}
"use strict";
//Javascript concepts
//Hoisting
// function funz() {
// console.log(foo);
// var foo = "hello";
// console.log(foo);
// }
//Closure
// function parent() {
// var foo = "hello";
// function child() {
// console.log(foo + " world");
// }
// child();
// }
//this
function funzThis(name, age) {
console.log(this); //window
this.name = name;
console.log(this.age); //obj
}
funzThis();
var obj = { name: "Ephicacy", age: 25 };
funzThis.call(obj, "ephicacy1", 30);
//myFunz("hello");
//call, apply
//Reference
// var obj = { foo: 1 };
// var myObj = obj;
// myObj.foo = 2;
// console.log(obj); // { foo: 2 }
//Inheritance
// function parent() {
// this.name = "parent";
// }
// parent.prototype.print = function() {
// console.log(this.name);
// }
// function child() {
// this.name = "child";
// }
// child.prototype = Object.create(parent.prototype);
// var childIns = new child();
// console.log(childIns);
//Loop
// var obj = { name : "Gokul", age : 25}
// for (var i in obj) {
// console.log(obj[i]); //print gokul, 25
// }
// //But using for of we sould be careful, because for of iterates till prototype chain
// // So use hasOwnproperty(); to avoid it
//ES6
//Fat Arrow
// (() => { alert("From fat arrow") });
//Maps this automatically for us
//No need for .bind();
//Object
// var options = {name : 'Bar'};
// var obj = {
// // Shorthand for options: options
// options,
// // Shorthand for Methods
// printName() {
// console.log("printName");
// }
// };
// obj.printName(); //printName
//Parameters
// function funz(a, b = 5) {
// console.log(a + b); //print 6
// }
// // Equivalent to: b === 5 if b is undefined or not passed
// funz(1);
//Variables = let, const
// var obj = {
// name: 'Gokul',
// age: 21,
// car: 'Swift'
// };
// //let is block level variable here
// for (let i in obj) {
// console.log(i); //print name age car
// }
// console.log(i); //i is not defined
//Const
// const bar = 'Hello';
// console.log(bar); //print Hello
// bar = 'World'; //"bar" is read-only
//Template string
// var name = 'Foo';
// var multiLineString = `Hello ${name}
// asdasdas`;
// console.log(multiLineString);
//Iterators
// for (let i of [1, 2, 3]) {
// console.log(i); //1 2 3
// }
//Promise
//Creating a promise object
//sequential asynchronous operations in javascript
// var promise = new Promise(function(resolve, reject) {
// //Making an ajax call
// $.ajax({
// url : 'https://api.github.com/users/gokulkrishh',
// method: 'get'
// })
// .success(function (response) {
// resolve(response); //Return response
// })
// .error(function (error) {
// reject(error); //Return error
// });
// });
// //Then callback to listen to resolve or rejected state
// promise.then(function (response) {
// console.log('Success -->', response);
// },
// //Reject callback
// function (error) {
// console.log('Error -->', error);
// })
// //To handle error
// .catch(function (e) {
// console.log(e);
// });
//Inheritance
// class Parent {
// print() {
// console.log('I am a class');
// }
// }
// Parent(); //Type error: Cannot call a class as a function
// var myParent = new Parent(); //Use `new` keyword to use class as construtor
// new Parent().print(); //print I am a class
//Modules
//Export
// export function printName(msg) {
// console.log('My name is ' + msg);
// }
//export var myDefaultName = 'Foo';
//Import
// import {myDefaultName, printName as printMyName} from './myFunz';
// printMyName('Bar'); //print My name is Bar
// console.log(myDefaultName); //print Foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment