Skip to content

Instantly share code, notes, and snippets.

/*
1. create prototype object
2. should itterate through object, aka forEach only for objects
obj.each(function(prop, val) {
console.log( prop ); // name -> age
});
*/
Object.prototype.each = function(f) {
/*
1. add defer() to all function prototypes
2. should wait for n second, then invoke a function
function f() {
console.log( 'Hello' );
}
f.defer(1000); //after delay 1sec 'Hello'
*/
/*
1. add defer() to all function prototypes
2. should wait for n second, then invoke a function
3. (!) and return a function
function f() {
console.log( a + b );
}
f.defer(1000)(1, 2); //after delay 1sec, 3
*/
Function.prototype.defer = function(ms) {
// 1. constructor
function Animal(name) {
this.name = name;
this.speed = 0;
}
// 2. methods in prototype
Animal.prototype.run = function(speed) {
this.speed += speed;
console.log(`${this.name} runnig, speed is ${this.speed}`);
function Animal() { };
var animal = new Animal();
/*
creates automatically
Animal.prototype = {
constructor: Animal
}
*/
function Animal() { }
Animal.prototype = {}; // override
var animal = new Animal();
console.log( animal.constructor == Animal ); // false
console.log( animal.constructor == Object ); // true
// 1. constructor Animal
function Animal(name) {
this.name = name;
this.speed = 0;
}
// 1.1. prototype methods
Animal.prototype.stop = function() {
this.speed = 0;
alert( this.name + ' stops' );
@qetr1ck-op
qetr1ck-op / berlin-jsconf-2014.md
Created October 3, 2015 10:35 — forked from nikcorg/berlin-jsconf-2014.md
Slide decks of JSConf 2014
angular.module('myApp', [])
.run(function($rootScope) {
$rootScope.globalVar = `I'm the global variable`;
});
<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:WebservicesName"> <!-- service name -->
<soap:Header>
<m:Trans xmlns:m="http://schemas.xmlsoap.org/soap/encoding/">Header</m:Trans>
</soap:Header>
<soapenv:Body>