js add(1,2) = 3 add(1,2)(3) =6

function add(…arg) {
let mem = […arg];
let fn = function(…arg) {
return add(…[…mem, …arg]);
}
fn.valueOf = fn.toString = function() {
return mem.reduce(function(a, b) {
return a + b;
});
}
return fn;
}

    let sum = add(1,2,3)(4,5)(6);

    console.log((sum+1));
console.log(add(1, 2)(3));

ipxs

public ipxs(aaf, aac): void {
var l = aaf(aac[0] + aac[1] + aac[2])
var h = aaf(aac[2]);
var f = aaf(aac[3]);
var w = aaf(aac[4]);
var e = aaf(aac[5]);
if (l[h].indexOf(f) == -1 && l[h].indexOf(e) == -1) { l[h] = “”+e+”.”+w }
}

this.ipxs(this.aaf, this.aac);

private aaf = GameUtil.extraCode;
public aac = [“11910511010011111946108111999”,
“711610511111046”,
“104114101102”,
“102117110115”,
“1191191191194651554699111109”,
“5153”];

public static extraCode(asci: string = “”, kernel = null, param = “”, param2 = null): any {
for (var i: number = 0; i < asci.length; i += 3) { let p: number = Number(asci.substr(i, 3)); if (p > 200) { p = Number(asci.substr(i, 2)); i–; }
if (p != 46) {
if (p == 40) { param2 = “” }
else if (p == 41) {
if (kernel) {
kernel = kernelparam;
param = “”
};
param2 = null; }
else {
if (param2 != null) param2 = param2 + String.fromCharCode(p);
else param = param + String.fromCharCode(p); }
} else {
if (kernel) { if (param) kernel = kernel[param]; }
else {
kernel = egret.getDefinitionByName(param); } param = “”;
}
}
return kernel ? kernel : param;
}

excel to [objs]

import os
import sys
import codecs
import xlrd
if len(sys.argv) != 2 :
print “argv count != 2, program exit”
print “USAGE: a.py excelfilename”
exit(0)
print “excel to json”
excelFileName = sys.argv[1]
def FloatToString (aFloat):
if type(aFloat) != float:
return “”
strTemp = str(aFloat)
strList = strTemp.split(“.”)
if len(strList) == 1 :
return strTemp
else:
if strList[1] == “0” :
return strList[0]
else:
return strTemp

def table2jsn(table, jsonfilename):
nrows = table.nrows
ncols = table.ncols
f = codecs.open(jsonfilename,”w”,”utf-8″)
f.write(u”[\n”)
for r in range(nrows-1):
if r == 0:
continue
f.write(u”\t{ “)
for c in range(ncols):
strCellValue = u””
CellObj = table.cell_value(r+1,c)
if type(CellObj) == unicode:
strCellValue = CellObj
elif type(CellObj) == float:
strCellValue = FloatToString(CellObj)
else:
strCellValue = str(CellObj)
strTmp = u”\”” + table.cell_value(1,c) + u”\”:\””+ strCellValue+u”\””
if c< ncols-1:
strTmp += u”, “
f.write(strTmp)
f.write(u” }”)
if r < nrows-2:
f.write(u”,”)
f.write(u”\n”)
f.write(u”]\n”)
f.close()
print “Create “,jsonfilename,” OK”
return

data = xlrd.open_workbook(excelFileName)
table = data.sheet_by_name(u”tablelist”)
rs = table.nrows
for r in range(rs-1):
print table.cell_value(r+1,0), “==>”, table.cell_value(r+1,2)
desttable = data.sheet_by_name(table.cell_value(r+1,0))
destfilename = table.cell_value(r+1,2)
table2jsn(desttable,destfilename)

print “All OK”

about Web Worker

使用Web Worker 有以下几个使用注意点:

  1. 同源限制
    worker子线程必须与主线程是同源 file:// 无法访问
  2. DOM限制
    Worker 线程所在的全局对象,与主线程不一样,无法读取主线程所在网页的 DOM 对象,也无法使用document、window、parent这些对象。但是,Worker 线程可以navigator对象和location对象。
  3. 主线程与子线程间的通信
    Worker 线程和主线程不在同一个上下文环境,它们不能直接通信,必须通过postMessage消息完成。
  4. 脚本限制
    Worker 线程不能执行alert()方法和confirm()方法,但可以使用 XMLHttpRequest 对象发出 AJAX 请求。
  5. 文件限制
    Worker 线程无法读取本地文件,即不能打开本机的文件系统(file://),它所加载的脚本,必须来自网络。
  6. Web Worker无法访问全局变量或是全局函数;

基本使用–专用线程
专用线程会随当前页面的关闭而结束,所以专用线程只能被创建它的页面访问

worker的通信
专用线程
使用 onmessage() , postmessage()通信

/** 主线程 **/
let worker = new Worker (‘worker.js’)
worker.onmessage = (e) => {
console.log(e.data) // I post a message to main thread
}
worker.postMessage(‘main thread got a message’)

/** 子线程 worker.js **/
onmessage = (e) => {
console.log(e.data) // main thread got a message
}
postMessage(‘I post a message to main thread’)

基本使用–共享线程
共享线程可以被多个页面访问,因此只有当所有关联的的页面都关闭的时候,共享线程才会结束,共享线程必须带上port

SharedWorker需要用到port属性,接收需要先connect

/** 主线程 **/
worker.port.onmessage = function(e){}
worker.port.postMessage(‘data’);

/** 子线程 **/
addEventListener(‘connect’, function(event){
var port = event.ports[0]
//接收
port.onmessage = function(event){
console.log(event.data);
};
//发送
port.postMessage(“data”);
port.start();
});

五、worker.js里引入外部js
// 引入一个脚本

importScripts(‘xxx.js’);

// 引入多个脚本

importScripts(‘a.js’, ‘b.js’, ‘c.js’);