Farid Ahmadian / DevOps

Java Script


CallBack Functions


<!DOCTYPE html>
<html>
<body>

<p>Click the button to wait 2 * 3 seconds, then alert "Hello".</p>

<button onclick="myFunction()">Try it</button>

<script>


function myFunction() {
    var date = new Date();
    console.log("#1 " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds());
    setTimeout(function(){myFunction3(myFunction2)}, 3000);
}

function myFunction3(callback) {
    var date = new Date();
    console.log("#3 " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds());
    setTimeout(callback, 3000);
}

function myFunction2() {
    var date = new Date();
    console.log("#2 " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds());
    alert("Hello");
}
</script>

</body>
</html>

Grunt


npm install -g grunt-cli
npm install -S grunt
npm init
npm install grunt-contrib-concat --save-dev
npm install grunt-contrib-uglify --save-dev
npm install grunt-contrib-htmlmin --save-dev

Gruntfile.js

module.exports = function (grunt) {
// Project configuration. 
grunt.initConfig({

  concat: {
    js: {
      src: ['ui/modules/**/*.js'],
      dest: 'dist/built.js',
    },
    css: {
      src: ['ui/css/**/*.css'],
      dest: 'dist/built.css',
  },
 },
 uglify : { 
    my_target: {
      files: {
        'dist/built-min.js': ['dist/built.js']
      }
    }
},
 htmlmin: {                                     // Task 
    dist: {                                      // Target 
      options: {                                 // Target options 
        removeComments: true,
        collapseWhitespace: true
      },
      files: {                                   // Dictionary of files 
        'templates/index-min.html': 'templates/index.html'     // 'destination': 'source' 
      }
    },
  }
});

    grunt.loadNpmTasks('grunt-contrib-htmlmin');    
    grunt.loadNpmTasks('grunt-contrib-uglify');
     grunt.loadNpmTasks('grunt-contrib-concat');    
    grunt.registerTask('both',['speak','yell']); 

    grunt.registerTask('speak',function() {
        console.log("I'm Speaking");
    });

    grunt.registerTask('yell',function() {
        console.log("I'm yelling");

    });


};

BY: Farid Ahmadian
TAG: javascript, callback, grunt
DATE: 2016-08-27 19:36:53


Farid Ahmadian / DevOps [ TXT ]

With many thanks and best wishes for dear Pejman Moghadam, someone who taught me alot in linux and life :)