- Use new to create an object x. Then x’s prototype is what?
Why can’t I do this x.prototype.some_method=…;
| # nl(s) is short for necklace(s) | |
| # generate all candidate necklaces | |
| def nls_init(n, m, necklaces = ['']): | |
| if not m: return map(lambda x: n*'1'+x, necklaces) | |
| if not n: return map(lambda x: m*'0'+x, necklaces) | |
| n1 = nls_init(n, m-1, map(lambda x: '0'+x, necklaces)) | |
| n2 = nls_init(n-1, m, map(lambda x: '1'+x, necklaces)) | |
| return n1 + n2 |
| var jsmin = function (js_string) { | |
| js_min = { | |
| holder: '/*wenjun.yan*/', // the minified js | |
| pos: 0, // current position | |
| chr: ' ', // current char | |
| js_string: js_string, // unminified js | |
| specs: ["'", '"', '{', '}', '(', ')', | |
| '[', ']', '+', '-', '*', '/', | |
| ':', '?', '!', '|', '&', '\\',';'], |
Why can’t I do this x.prototype.some_method=…;
| var string_automata = function (string) { | |
| var length = string.length; | |
| var init = string[0]; | |
| var automata = []; | |
| automata[0][init] = [1]; | |
| // var get_state_by_id = function (id) { | |
| // return automata[id]; | |
| // } | |
| main() | |
| { | |
| for (;;) { | |
| if (getchar() == EOF) return TRUE; | |
| if (getchar() == EOF) return FALSE; | |
| } | |
| } |
| WHILE current char : a | |
| stepin blank: | |
| step in next: | |
| step out next: a | |
| stepout blank: a | |
| BLANK current char : a | |
| WHILE current char : a r | |
| ERROR current char : a | |
| error4 |
| ;;; THIS gist is from Xah Emacs Tutorial | |
| ;;; http://ergoemacs.org/emacs/emacs.html | |
| (defun run-current-file () | |
| "Execute or compile the current file. | |
| For example, if the current buffer is the file x.pl, | |
| then it'll call “perl x.pl” in a shell. | |
| The file can be php, perl, python, ruby, javascript, bash, ocaml, vb, elisp. | |
| File suffix is used to determine what program to run. |
| // get properties of an object; | |
| // if f(property) is true; | |
| var get_props_if = function (obj, f) { | |
| f = f || function (arg) {return true;}; | |
| var holder = []; | |
| for (var p in obj) if (f.call(obj, p)) { | |
| holder.push(p); | |
| } |
| (defun only-current-buffer () | |
| (interactive) | |
| (mapc 'kill-buffer (cdr (buffer-list (current-buffer))))) | |
| (defun plist-to-alist (the-plist) | |
| (defsubst get-tuple-from-plist (the-plist) | |
| (when the-plist | |
| (cons (car the-plist) (cadr the-plist)))) | |
| (let ((alist '())) | |
| (while the-plist | |
| (add-to-list 'alist (get-tuple-from-plist the-plist)) | |
| (setq the-plist (cddr the-plist))) | |
| alist)) |