Home >Web Front-end >JS Tutorial >js callback simple code example

js callback simple code example

小云云
小云云Original
2018-03-07 10:28:451352browse

This article mainly shares a simple code with you, which is a simple code example for js callback. I hope this code can help everyone.

function test(callback) {
   var data = "aaa";
  typeof callback == 'function' && callback(data)
    }



test(function (data) {

  console.log(data);

 });
typeof  callback   输出callback的类型
== 'function'        
等于function(函数)&& callback(data)         
&&前面的为真,则执行&&后面的语句 callback(data),  data为需要传递的函数参数,

Related recommendations:

JS callback asynchronous

A simple example of the application of JS callback function_javascript skills

Blocking and non-blocking calls of node.js callback functions_node.js

The above is the detailed content of js callback simple code example. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Summary of using Pixi.jsNext article:Summary of using Pixi.js