JSFiddle

  • Recursion

    No-Library (pure JS), HTML, CSS, JavaScript

    const fact = (num) => {
    	// terminal case
      if (num <= 0) return 1;
      // block to execute
      return num * fact(num - 1);
    };
    i.onchange = e => o.value = fact(+e.target.value)
  • URL & URLSearchParams

    No-Library (pure JS), HTML, CSS, JavaScript

    let url = new URL('https://g.cn/foo?bar=tar');
    console.log(url)
    let urlSearchParams = new URLSearchParams('a=111&b=222');
    urlSearchParams ...
  • Cloning variables in JavaScript

    No-Library (pure JS), HTML, CSS, JavaScript

    // Array
    var a=[1],b;
    b=Array.concat(a);
    b.push(2);
    console.log('a:',a,'b:',b)
    
    // Object
    var ...
  • Shim for :placeholder-shown

    Add .placeholder-shown class to the text field elements then value is set

    +function($){
        if ($('html').hasClass('lte9')) {
            /* LTE IE9 */
            /*
             * Shim for :placeholder-shown
             * Add .placeholder-shown class to the text field elements then value ...
  • Angular bootstrap

    AngularJS 1.2.1, HTML, CSS, JavaScript

    var now = new Date(),
        grp = now.getTime();
    
    console.group(grp);
    angular.module('a', [], function(){
        console.log('module a', arguments);
    });
    
    angular ...
  • Angular: Using fake backend

    http://angularjs.org/

    var app = angular.module('myApp', ['ngMockE2E']);
    
    // define our fake backend
    app.run(function($httpBackend) {
    
      var phones = [{name: 'phone1'}, {name: 'phone2 ...
  • #JS8cB #5 is the latest revision

    No-Library (pure JS), HTML, CSS, JavaScript

    module.exports=
    /*.............
    ...............
    ...............
    ...............
    .............*/
    
    function (){/*......
    ....................
    ....................
    .PUT.YOUR.CODE.HERE.
    ....................
    ....................
    .................*/}
  • OOP #2 is the latest revision

    Encapsulation, inheritance and polymorphism Инкапсуляция, наследование и полиморфизм

    Function.prototype.extends = function (Parent) {
        var F = function () {};
        F.prototype = Parent.prototype;
        this.prototype = new F();
        this.prototype.constructor = this ...
  • Tips and Tricks: Binding loss (this)

    No-Library (pure JS), HTML, CSS, JavaScript

    /* 1. What sence of "var" here? */
    name = 'John';
    var myObject = ({
        name: "Ted",
        baz: function Bob(n) {
            console.log(n + ".1 ...
  • SVG Font Viewer #95 is the latest revision

    Show all defined glyph in font, its name and unicode

    var doc = document.documentElement;
    var toload = 0;
    var loaded = 0;
    var target = document.body;
    
    var createSVG = function (charsvg, ex, em ...