<commit_before>
$(function(){

  myModule();
  mapTest();
  eventProp();
  handleTest();

})

//-------------------
// event bubbling
//-------------------

var eventProp = function (){

  var divElements = document.getElementsByClassName('divStyle')
  console.log(divElements)

  for(var i=0; i < divElements.length; i++){
    divElements[i].onclick = function(evt){
      evt = evt || window.evt; //ie8 get the evt object

      if(evt.stopPropagation){ // if this is supported use this ie9 other browsers
        evt.stopPropagation();
      }
      else {
        evt.cancelBubble = true // else use this one
      }
      this.style.borderColor = "red";
      alert(this.getAttribute("id") + " border color changed")
    }
  }

}

//-------------------
// map function
//-------------------

var mapTest = function(){

  var myArray = [4,3,5,2,1]

  var newArray= myArray.map(function(num){
    return num * 2;
  })

  console.log(myArray)
  console.log(newArray)

}

//-------------------
// handlebar example
//-------------------


var handleTest = function (){

  var source= $("#new_template").html();
  var template = Handlebars.compile(source);

  var context = {
    title: "this is our title from far away",
    body: "this is our sexy body"
  }

  var el_html = template(context);

  $("#render_one").html(el_html);

}


//-------------------
// classic module patern example
//-------------------

var myModule = function () {

  var foo = (function(){

    var o = { bar: "bar"};

    return {
      bar: function(){
        console.log(o.bar);
      }
    };
  })();

  foo.bar();

}

// one outer wrapping function
// two functions have to be return that have a closure over private scope
// access the internal state and that is called a module<commit_msg>add example of simple unit test<commit_after>
$(function(){

  myModule();
  mapTest();
  eventProp();
  handleTest();

})

//-------------------
// event bubbling
//-------------------

var eventProp = function (){

  var divElements = document.getElementsByClassName('divStyle')
  console.log(divElements)

  for(var i=0; i < divElements.length; i++){
    divElements[i].onclick = function(evt){
      evt = evt || window.evt; //ie8 get the evt object

      if(evt.stopPropagation){ // if this is supported use this ie9 other browsers
        evt.stopPropagation();
      }
      else {
        evt.cancelBubble = true // else use this one
      }
      this.style.borderColor = "red";
      alert(this.getAttribute("id") + " border color changed")
    }
  }

}

//-------------------
// map function
//-------------------

var mapTest = function(){

  var myArray = [4,3,5,2,1]

  var newArray= myArray.map(function(num){
    return num * 2;
  })

  console.log(myArray)
  console.log(newArray)

}

//-------------------
// handlebar example
//-------------------


var handleTest = function (){

  var source= $("#new_template").html();
  var template = Handlebars.compile(source);

  var context = {
    title: "this is our title from far away",
    body: "this is our sexy body"
  }

  var el_html = template(context);

  $("#render_one").html(el_html);

}


//-------------------
// classic module patern example
//-------------------

var myModule = function () {

  var foo = (function(){

    var o = { bar: "bar"};

    return {
      bar: function(){
        console.log(o.bar);
      }
    };
  })();

  foo.bar();

}

// one outer wrapping function
// two functions have to be return that have a closure over private scope
// access the internal state and that is called a module

//---------------------------
//  Simple unit test
//---------------------------
var Bob = require('./bob.js');
describe("Bob", function() {
  var bob = new Bob();
  it("stating something", function() {
    var result = bob.hey('Tom-ay-to, tom-aaaah-to.');
    expect(result).toEqual('Whatever.');
  });
});
{'fraction_non_alphanumeric': 0.23021397267336943, 'fraction_numerical': 0.004640371229698376, 'mean_word_length': 1.9416224412433662, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2022814', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1162, 'n_words': 318}