Skip to content

Instantly share code, notes, and snippets.

@PavanKu
PavanKu / markdown.md
Created August 25, 2016 08:30 — forked from jonschlinkert/markdown-cheatsheet.md
A better markdown cheatsheet. I used Bootstrap's Base CSS documentation as a reference.

Typography

Headings

Headings from h1 through h6 are constructed with a # for each level:

# h1 Heading
## h2 Heading
### h3 Heading
@PavanKu
PavanKu / global.js
Created December 26, 2017 05:32
IIFE (Immediately Invoked Function Expression)
(function(){
console.log("Anonymous function invocation");
console.log(this === window);
})();
// Prints true on console
@PavanKu
PavanKu / strict.js
Created December 26, 2017 05:34
Strict Mode in JS
function foo () {
'use strict';
console.log("Simple function call")
console.log(this === window);
}
foo(); //prints false on console as in “strict mode” value of “this” in global execution context is undefined.
@PavanKu
PavanKu / newInstance.js
Created December 26, 2017 05:37
this in Constructor method
function Person(fn, ln) {
this.first_name = fn;
this.last_name = ln;
this.displayName = function() {
console.log(`Name: ${this.first_name} ${this.last_name}`);
}
}
let person = new Person("John", "Reed");
@PavanKu
PavanKu / call.js
Created December 26, 2017 05:44
this with Call and Apply
function Person(fn, ln) {
this.first_name = fn;
this.last_name = ln;
this.displayName = function() {
console.log(`Name: ${this.first_name} ${this.last_name}`);
}
}
let person = new Person("John", "Reed");
@PavanKu
PavanKu / bind.js
Created December 26, 2017 05:46
this with bind method
function Person(fn, ln) {
this.first_name = fn;
this.last_name = ln;
this.displayName = function() {
console.log(`Name: ${this.first_name} ${this.last_name}`);
}
}
let person = new Person("John", "Reed");
@PavanKu
PavanKu / ex.js
Created December 26, 2017 05:48
Example for this
function multiply(p, q, callback) {
callback(p * q);
}
let user = {
a: 2,
b:3,
findMultiply: function() {
multiply(this.a, this.b, function(total) {
console.log(total);
@PavanKu
PavanKu / global.js
Created December 26, 2017 05:49
Global value
var count = 5;
function test () {
console.log(this.count === 5);
}
test() // Prints true as “count” variable declaration happened in global execution context so count will become part of global object.
@PavanKu
PavanKu / contact.spec.ts
Created January 22, 2018 04:22
Unit Testing of Model Class In AngularJS V5
import { Contact } from './contact';
describe('Contact', () => {
it('should create an instance', () => {
expect(new Contact()).toBeTruthy();
});
it('should accept values from constructor', () => {
let contact = new Contact({
firstName: 'John',
@PavanKu
PavanKu / address-book-data.service.spec.ts
Created January 22, 2018 04:24
Unit Testing of Service in AngularJS V5
import { TestBed, inject } from '@angular/core/testing';
import { AddressBookDataService } from './address-book-data.service';
import { Contact } from '../models/contact';
describe('AddressBookDataService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [AddressBookDataService]
});