callback

Callback this context [duplicate]

泄露秘密 提交于 2020-01-30 02:47:20
问题 This question already has answers here : How to access the correct `this` inside a callback? (10 answers) Closed 3 years ago . in App: var bootstrap = new Bootstrap(); bootstrap.init( this, this.onBootstrapComplete ); in Bootstrap: this.init = function( app, completeHandler ){ _app = app; _completeHandler = completeHandler; ... } ... var _allReady = function(){ _completeHandler( _app ); } back in App: this.onBootstrapComplete = function( app ) { app.something(); app.someValue = ... } I wanted

Node.js学习笔记(五) http模块

孤街醉人 提交于 2020-01-29 23:24:41
这篇文章我们将会学习 Node 的内置模块 http,http 模块主要用于 搭建 HTTP 服务端和客户端 1、http 服务端 (1)创建服务 http 服务端通过 http.Server 实现,我们可以通过以下两种方法创建一个 http.Server const http = require('http') // 方法一 var server = new http.Server() // 方法二 var server = http.createServer() (2)绑定事件 http.Server 是一个 基于事件 的服务器,我们需要为不同的事件指定相应的处理函数,即可完成功能 最常用的事件莫过于 request ,当服务器获取到请求时,就会触发该事件 事件处理函数接收两个参数,分别对应 http.IncomingMessage 和 http.ServerResponse server.on('request', function(message, response) { console.log(message instanceof http.IncomingMessage) // true console.log(response instanceof http.ServerResponse) // true console.log('收到请求') }) (3)属性方法

HTML系列(四):编辑图像

南楼画角 提交于 2020-01-29 20:26:43
一、图像的基本概念 1、矢量图:文件占用空间小,放大后图像不会失真,和分辨率无关。适用于图形设计、文字设计、标志设计、版式设计等。 2、位图:由像素点组成,文件较大,放大和缩小图像会失真。 3、有损压缩图像:允许压缩过程损失一定的不敏感信息。JPEG和JPG是最常见的采用有损压缩进行处理的图片格式。 4、无损压缩图像:记录图像上每个像素点的数据信息,采用特殊的算法来压缩文件大小。PNG是最常见的采用无损压缩的图片格式。 5、常见格式的图像:JPEG/JPG是网页中常见的图像格式,以24位存储单个位图,支持数百万种颜色,适用于具有颜色过渡的图像或有256种以上颜色的图像,不支持透明和动画,支持隔行扫描。GIF最多包含256种颜色,支持透明度和多个动画帧,适用于卡通、徽标、包含透明区域的图形或动画。PNG最多支持32位颜色,支持真彩色和调色板,支持完全的Alpha透明,支持动画,支持隔行扫描。 二、插入图像 img 元素向网页中嵌入一幅图像。从技术上讲,<img> 标签并不会在网页中插入图像,而是从网页上链接图像。<img> 标签创建的是被引用图像的占位空间。<img> 标签有两个必需的属性:src 属性 和 alt 属性。当指定的URL图像加载失败时,alt属性显示定义的文本。 如果图片需要有标题,可以使用figure和figcaption来语义化地表示带标题的图片。<figure>

自研模块加载器(三) module模块构造器设计-模块数据初始化

倾然丶 夕夏残阳落幕 提交于 2020-01-29 16:22:30
依赖加载策略 模块数据初始化 status状态生命周期 代码展示 demo包括4个文件, index.html , a.js , b.js , startUp.js index.html <!DOCTYPE html> <html> <head> <title>自研模块加载器</title> </head> <body> <script src="./startUp.js"></script> <script> startUp.use(['a.js', 'b.js'], function() { console.log('startUp...') }) </script> </body> </html> a.js define(function(require, exports, module) { var a = { who: "我" } exports(a) }) b.js define(function(require, exports, module) { var b = { text: "太难了" } exports(b) }) startUp.js (模块加载器) (function(global) { var startUp = global.startUp = { version: '1.0.1' } var data = {}; // 获取当前模块加载器内置信息

MongoDB入门以及简单案例

浪子不回头ぞ 提交于 2020-01-29 04:32:18
MongoDB 1、什么是MongoDB MongoDB是一个基于分布式文件存储 的数据库。是为了快速开发互联网web应用而设计的数据库系统。 MongoDB的设计目标是极简、灵活、作为Web应用栈的一部分。 MongoDB的数据模型是面向文档的,所谓文档是一种类似于JSON的结构,简单理解MongoDB这个数据库中存的是各种各样的JSON 2、三个概念 数据库 –数据库是一个仓库,在仓库中可以存放集合 集合 –集合类似于数组,在集合中可以存放文档。 文档 –文档数据库中的最小单位,我们存储和操作的内容都是文档。 3、基本指令 在MongoDB中,数据库和集合都不需要自己手动创建,当我们创建文档时,如果所在的集合或数据库不存在会自动的创建数据库和集合。 show dbs :显示当前的所有数据库 use 数据库 :进入到指定的数据库中 db :db表示的是当前所处的数据库 show collections :显示数据库中所有的集合。 MongoDB的CRUD操作详情请看官方文档 3.1、插入操作 db.集合.insert({key:value}),向集合中插入一个或者多个文档 当我们向集合中插入文档时,如果没有给文档指定_id属性,则数据库会自动为文档添加_id属性来作为文档的唯一标识(该id是以时间戳和机器码来生成的), 我们可以调用ObjectId()来生成 3.2、查找集合

Does MySQL permit callbacks in C such that when a change happens, I can be notified?

£可爱£侵袭症+ 提交于 2020-01-28 08:05:09
问题 Does MySQL permit callbacks in C such that when a change happens in the database, like an insert, that is performed by a different program or by the user at the command line, I can be notified? I am guessing that it doesn't, because mysqlclient is a library, not a running thread. But I may as well ask. 回答1: Create a trigger like so. DELIMITER $$ CREATE TRIGGER ad_mytable_each AFTER DELETE ON MyTable FOR EACH ROW BEGIN #write code that trigger After delete (hence the "ad_" prefix) #For table

关于新型冠状病毒肺炎疫情追踪的可视化数据的采集、处理

帅比萌擦擦* 提交于 2020-01-27 14:57:40
关于新型冠状病毒肺炎疫情追踪的可视化数据的采集、处理 最终效果图 数据来源:https://news.qq.com/zt2020/page/feiyan.htm 数据采集:使用谷歌浏览器自带的开发者工具进行数据包抓取 采集过程:进入网页后,使用开发者工具进行数据包捕获, 按钮为红色即说明进入捕获状态,接着我们刷新一下页面 可以发现里面有很多数据包,我们需要的数据是全国确诊人数、疑似病例、治愈人数等等数据,那么如何抓取我们需要的数据呢? 其实在开发者工具里有一个搜索按钮,如下图 接着利用它来搜索我们需要的数据,比如全国确诊的数据 接着我们看搜索结果的第一条的Response的内容,可以发现这是条json数据,确认后发现,这些数据这正是网页数据的来源。 在其Hearders中可以看到,其传递数据的方式是Get,我们可以直接复制它的URL,分析其中传递的参数 URL:https://view.inews.qq.com/g2/getOnsInfo?name=wuwei_ww_global_vars&callback=jQuery3410890567228054113_1580091530788&_=1580091530789 可以发现其中有两个参数,name与callback,其中从其callback参数传递的内容发现,这是一个关于时间的参数,

Tkinter crashing on garbage collected variable: _tkinter.TclError: can't set “PY_VAR1”:

六月ゝ 毕业季﹏ 提交于 2020-01-26 04:45:49
问题 I'm attempting to write a widget using Tkinter. The script uses an .ini file to store some saved settings. The interface allows the user to enter a new name to a dropdown menu, and save some text strings associated with it. A stripped down version is linked below. I'm using String variables to track the changes to input fields. The issue I'm seeing is that occasionally, when a user goes to add another custom entry, the script will crash when attempting to update the text field with some

Returning an object from a callback using async/await

北城余情 提交于 2020-01-26 03:54:07
问题 I can't resolve this question with the answers to this question because there are differences in the code. I want to return an object out of a callback. When I run the below code, the log of the body object looks as expected. It appears to be the correct JSON object containing the response I want from the server: name, email, website, etc. But the result object appears to contain information about the request itself instead of the response object. How do I return the body object so that I can

Call non static method dynamically

只愿长相守 提交于 2020-01-25 21:05:19
问题 i tried to call non static method like that: call_user_func_array(array("Notifications", "getNots"), $params) and i got error: call_user_func() expects parameter 1 to be a valid callback, non-static method... the function is: class Notifications { public function getNots($limit, $test = 0) { } } what to do? actually i tried to built function that got html code of html page and replace all texts like that: {{ Notifications.getNotes(3) }} to method return... tnx a lot 回答1: To do this with a non