-
Notifications
You must be signed in to change notification settings - Fork 1
/
bundle.js
11182 lines (9147 loc) · 286 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
const Befunge93 = require('befunge93');
const $ = require('jquery');
let program = $('#program');
let interpreter = $('#interpreter');
let stack = $('#stack');
let output = $('#output');
let buttonRun = $('#run');
let buttonPause = $('#pause');
let buttonPlay = $('#play');
let buttonStep = $('#step');
let buttonReset = $('#reset');
let buttonClear = $('#clear');
let buttonCrawl = $('#crawl');
let buttonToggleMode = $('#toggleMode');
let editorButtons = [buttonClear];
let interpreterButtons = [buttonRun, buttonReset, buttonPause, buttonPlay, buttonStep, buttonCrawl];
let interpreterMode = false;
let befunge = new Befunge93(onStackChange, onOutput, onCellChange, onStep, onInput);
let lastCell;
let running = false;
let delay = 1;
interpreter.width(program.width());
interpreter.height(program.height());
attachEventListeners();
function onStackChange(_stack) {
stack.text(_stack.join(" "));
}
function onOutput(_output) {
output.text(output.text() + _output);
}
function onInput(_message) {
return prompt(_message);
}
function onCellChange(_x, _y, newValue) {
let currentCell = $(`#c${_y * 80 + _x}`);
currentCell.text(newValue);
}
function onStep(_x, _y) {
if (lastCell) {
lastCell.removeClass("active-cell");
}
let currentCell = $(`#c${_y * 80 + _x}`);
currentCell.addClass("active-cell");
lastCell = currentCell;
}
function toggleInterpreterMode() {
interpreterMode = !interpreterMode;
program.toggleClass("invisible");
interpreter.toggleClass("invisible");
toggleEditorButtons();
toggleInterpreterButtons();
if (interpreterMode) {
resetPartialUI();
befunge.reset();
befunge.loadProgram(program.val());
interpreter.html(generateSpansFromProgram());
onStep(0,0);
buttonToggleMode.text("To Editor Mode");
} else {
befunge.pause();
buttonToggleMode.text("To Interpreter Mode");
}
}
function generateSpansFromProgram() {
let output = "";
for (let y = 0; y < 25; y++) {
for (let x = 0; x < 80; x++) {
output += `<span id='${"c" + (y * 80 + x) }'>${befunge.program[y][x]}</span>`;
}
output = output.replace(/\s+$/, '') + "\n";
}
return output;
}
function toggleInterpreterButtons() {
interpreterButtons.forEach((button) => {
button.toggleClass('disabled');
});
}
function toggleEditorButtons() {
editorButtons.forEach((button) => {
button.toggleClass('disabled');
})
}
function resetAllUI() {
output.text("");
program.val("");
stack.text("");
}
function resetPartialUI() {
output.text("");
stack.text("");
}
function playLoop() {
let bench = new Benchmark("Play");
bench.start();
befunge.stepInto();
let timeoutId = setTimeout(function loop() {
bench.tick();
befunge.stepInto();
if (befunge.hasNext) {
timeoutId = setTimeout(loop, delay);
} else {
console.log("Ended");
bench.end();
}
}, delay);
}
function onClickPlay() {
running = true;
delay = 0;
befunge.loadProgram(program.val());
playLoop();
}
function onClickCrawl(){
delay = 100;
running = true;
befunge.loadProgram(program.val());
playLoop();
}
function onClickRun() {
running = true;
resetPartialUI();
befunge.reset();
befunge.ignoreCallbacks = true;
let bench = new Benchmark("Run");
let tickCallback = () => {
bench.tick();
};
bench.start();
befunge.run(program.val(), true, tickCallback)
.then((output) => {
bench.end();
befunge.ignoreCallbacks = false;
onOutput(output);
onStackChange(befunge.stack);
});
}
function onClickStep() {
console.log("step clicked");
if (befunge.programLoaded === false) {
befunge.loadProgram(program.val());
}
befunge.stepInto(null, program.val());
}
function onClickClear() {
if (alert("Are you sure you want to clear everything?")) {
resetAllUI();
befunge.reset();
}
}
function onClickReset() {
resetPartialUI();
befunge.reset();
befunge.loadProgram(program.val());
}
function onClickPause() {
if(running){
buttonPause.text("Resume");
befunge.hasNext = false;
running = false;
} else {
buttonPause.text("Pause");
befunge.hasNext = true;
running = true;
playLoop();
}
}
function onClickToggleInterpreter() {
toggleInterpreterMode();
}
function attachEventListeners(){
buttonRun.click(function() {
onClickRun();
});
buttonPause.click(function() {
onClickPause();
});
buttonPlay.click(function() {
onClickPlay();
});
buttonStep.click(function() {
onClickStep();
});
buttonReset.click(function() {
onClickReset();
});
buttonClear.click(function() {
onClickClear();
});
buttonCrawl.click(function() {
onClickCrawl();
});
buttonToggleMode.click(function() {
onClickToggleInterpreter();
});
}
class Benchmark {
constructor(name) {
this.name = name;
this.startTime = null;
this.endTime = null;
this.elapsedTime = null;
this.ticks = 0;
}
start() {
this.startTime = (new Date()).getTime();
console.log(this.startTime);
}
end() {
this.endTime = (new Date()).getTime();
this.elapsedTime = this.endTime - this.startTime;
this.stats();
}
tick() {
this.ticks += 1;
}
stats() {
console.log(`-------BENCHMARKING-------`);
console.log(`Benchmark stats for ${this.name}:`);
console.log(`Start time: ${this.startTime}`);
console.log(`End time: ${this.endTime}`);
console.log(`Ticks: ${this.ticks}`);
console.log(`Elapsed time (ms): ${this.elapsedTime}`);
console.log(`Elapsed time (s) : ${this.elapsedTime / 1000}`);
console.log(`-------BENCHMARKING-------`);
}
}
},{"befunge93":2,"jquery":3}],2:[function(require,module,exports){
/**
* Creates a new Befunge93 interpreter
* @class
*/
class Befunge93 {
/**
* @constructor
* @param {Befunge93~onStackChange} [onStackChange] - Called when the stack is updated (pushed or popped). Supplies
* 1 arg, current stack
* @param {Befunge93~onOutput} [onOutput] - Called when output happens (, or . commands). Supplies 1 arg, the
* generated output
* @param {Befunge93~onCellChange} [onCellChange] - Called when program is changed (p command) Supplies 3 args,
* current x, current y, and the new value of the cell
* @param {Befunge93~onStep} [onStep] - Called when the interpreter makes a step (changing program cursor).
* Supplies 2 args the current X and Y values
* @param {Befunge93~onInput} [onInput] - Called when the interpreter needs user input. Supplies 1 arg, prompt
* message
*/
constructor(onStackChange = null, onOutput = null, onCellChange = null, onStep = null, onInput = null) {
this.onStackChange = onStackChange;
this.onOutput = onOutput;
this.onCellChange = onCellChange;
this.onStep = onStep;
this.onInput = onInput;
this.hasNext = false;
this.ignoreCallbacks = false;
this.output = "";
this.x = 0;
this.y = 0;
this.dX = 1;
this.dY = 0;
this.stack = [];
this.stringMode = false;
this.programLoaded = false;
this.program = function () {
let program = [];
for (let i = 0; i < 25; i++) {
program.push(new Array(80).fill(" "));
}
return program;
}();
}
/**
* Called when the stack is changed
* @callback Befunge93~onStackChange
* @param {array} stack - The current stack
* */
/**
* Called when the interpreter parses "." or ","
* @callback Befunge93~onOutput
* @param {string} value - The value that was output from interpreter
*/
/**
* @callback Befunge93~onCellChange
* @param {number} x - The changed cell's x position
* @param {number} y - The changed cell's y position
* @param {string} newValue - The changed cell's new value
*/
/**
* Called when the interpreter's cursor position is changed
* @callback Befunge93~onStep
* @param {number} x - Cursor's current X position
* @param {number} y - Cursor's current y position
*/
/**
* Called when the interpreter parses "~" or "&".
* @callback Befunge93~onInput
* @param {string} message - The message that will be displayed to the user; can be replaced by whatever you want
* @returns {string} Input from the user.
*/
/**
* Called every tick of the interpreter. Only useful for benchmarking
* @callback Befunge93~onTick
*/
/** @private
* @static */
static isHexDigit(value) {
let a = parseInt(value, 16);
return (a.toString(16) === value.toLowerCase());
}
/** @private */
_onStackChange() {
if (this.ignoreCallbacks) return null;
return this.onStackChange ? this.onStackChange(this.stack) : null;
}
/** @private */
_onOutput(value) {
this.output += value;
if (this.ignoreCallbacks) return null;
return this.onOutput ? this.onOutput(value) : null;
}
/** @private */
_onInput(message) {
if (this.onInput === null) {
throw new Error("You must supply an On Input callback if your code needs input! Else it will never work.");
}
return this.onInput(message);
}
/** @private */
_onCellChange(x, y, newValue) {
if (this.ignoreCallbacks) return null;
this.onCellChange ? this.onCellChange(x, y, newValue) : null;
}
/** @private */
_onStep() {
if (this.ignoreCallbacks) return null;
this.onStep ? this.onStep(this.x, this.y) : null;
}
/** @private */
pop() {
let v = this.stack.pop();
this._onStackChange();
if (v === undefined) {
return 0;
} else {
return v;
}
}
/** @private */
push(value) {
this.stack.push(value);
this._onStackChange();
}
/** @private */
step(doCallback = true) {
this.x += this.dX;
this.y += this.dY;
if (this.x >= 80) this.x = 0;
if (this.x < 0) this.x = 79;
if (this.y >= 25) this.y = 0;
if (this.y < 0) this.y = 24;
if (doCallback) {
this._onStep();
}
}
/** @private */
parseToken(token) {
if (this.stringMode) {
let char = token.charCodeAt(0);
if (char === 34) { // Char code for "
this.toggleStringMode();
} else if (char <= 255) {
this.push(char);
}
} else {
if (Befunge93.isHexDigit(token)) {
this.pushHexValueToStack(token);
} else {
switch (token) {
case " ":
return null;
case ">":
this.right();
break;
case "<":
this.left();
break;
case "^":
this.up();
break;
case "v":
this.down();
break;
case "?":
this.randomDirection();
break;
case "+":
this.add();
break;
case "-":
this.subtract();
break;
case "*":
this.multiply();
break;
case "/":
this.divide();
break;
case "%":
this.modulo();
break;
case "`":
this.greaterThan();
break;
case "!":
this.not();
break;
case "_":
this.horizontalIf();
break;
case "|":
this.verticalIf();
break;
case ":":
this.duplicate();
break;
case "\\":
this.swap();
break;
case "$":
this.discard();
break;
case ".":
this.outInt();
break;
case ",":
this.outAscii();
break;
case "#":
this.bridge();
break;
case "g":
this.get();
break;
case "p":
this.put();
break;
case "&":
this.inInt();
break;
case "~":
this.inAscii();
break;
case `"`:
this.toggleStringMode();
break;
case "@":
this.terminateProgram();
break;
}
}
}
}
/** @private */
pushHexValueToStack(token) {
this.push((parseInt(token, 16)));
}
/** @private */
add() {
let b = this.pop();
let a = this.pop();
this.push(a + b);
}
/** @private */
subtract() {
let b = this.pop();
let a = this.pop();
this.push(a - b);
}
/** @private */
multiply() {
let b = this.pop();
let a = this.pop();
this.push(a * b);
}
/** @private */
divide() {
let b = this.pop();
let a = this.pop();
if (b !== 0) {
this.push(Math.trunc(a / b));
} else {
this.push(0);
}
}
/** @private */
modulo() {
let b = this.pop();
let a = this.pop();
this.push(a % b);
}
/** @private */
not() {
if (this.pop()) {
this.push(0);
} else {
this.push(1);
}
}
/** @private */
greaterThan() {
let b = this.pop();
let a = this.pop();
if (a > b) {
this.push(1);
} else {
this.push(0);
}
}
/** @private */
right() {
this.dY = 0;
this.dX = 1;
}
/** @private */
left() {
this.dY = 0;
this.dX = -1;
}
/** @private */
up() {
this.dY = -1;
this.dX = 0;
}
/** @private */
down() {
this.dY = 1;
this.dX = 0;
}
/** @private */
randomDirection() {
let r = Math.random();
if (r <= 0.25) {
this.left();
} else if (r <= 0.50) {
this.right();
} else if (r <= 0.75) {
this.up();
} else if (r <= 1.00) {
this.down();
}
}
/** @private */
horizontalIf() {
if (this.pop()) {
this.left();
} else {
this.right();
}
}
/** @private */
verticalIf() {
if (this.pop()) {
this.up();
} else {
this.down();
}
}
/** @private */
toggleStringMode() {
this.stringMode = !this.stringMode;
}
/** @private */
duplicate() {
let a = this.pop();
this.push(a);
this.push(a);
}
/** @private */
swap() {
let b = this.pop();
let a = this.pop();
this.push(b);
this.push(a);
}
/** @private */
discard() {
this.pop();
}
/** @private */
put() {
let y = this.pop();
let x = this.pop();
let v = String.fromCharCode(this.pop() % 256);
this.program[y][x] = v;
this._onCellChange(x, y, v);
}
/** @private */
get() {
let y = this.pop();
let x = this.pop();
if ((0 <= x && x < 80) && (0 <= y && y < 25)){
this.push(this.program[y][x].charCodeAt(0));
} else {
this.push(0);
}
}
/** @private */
bridge() {
this.step();
}
/** @private */
outInt() {
return this._onOutput(this.pop().toString() + " ");
}
/** @private */
outAscii() {
return this._onOutput(String.fromCharCode(this.pop()));
}
/** @private */
inInt() {
this.push(parseInt(this._onInput("Enter integer: ")));
}
/**
* Converts user entry to char code and pushes to stack. If more than one character entered, only the first is used
* @private */
inAscii() {
this.push(parseInt(this._onInput("Enter ASCII character: ").charCodeAt(0)));
}
/** @private */
terminateProgram() {
this.hasNext = false;
}
loadProgram(data) {
let lines = data.split(/(?:\r\n)|(?:\r)|(?:\n)/);
for (let y = 0; y < lines.length; y++) {
for (let x = 0; x < lines[y].length; x++) {
this.program[y][x] = lines[y][x];
}
}
this.programLoaded = true;
this.hasNext = true;
return true;
}
/** @private */
getToken(x, y) {
if (!(0 <= x < 80) || !(0 <= y < 25)) {
throw new Error("Coordinates out of range!");
}
return this.program[y][x];
}
/** @private */
init(program) {
if (this.loadProgram(program)) {
this.hasNext = true;
this.programLoaded = true;
}
}
/** @public */
stepInto() {
let token = this.getToken(this.x, this.y);
if (this.stringMode) {
this.parseToken(token);
this.step();
} else {
if (token !== " ") {
this.parseToken(token);
this.step();
} else {
this.step();
}
if (this.getToken(this.x, this.y) === " ") {
this.stepInto();
}
}
}
/**
* Stops executing of the program
* @public */
pause() {
this.hasNext = false;
}
/**
* Allows execution of the program to continue. Does NOT actually proceed with execution
* @public */
resume() {
this.hasNext = true;
}
/**
*
* @param {string} program - The program to be run. Lines separated with \n, \r, or \n\r
* @param {boolean} [reset] - Reset interpreter to default before running?
* @param {function} [onTick] - Called every tick. Useful for benchmarking programs
* */
run(program, reset = false, onTick = null) {
return new Promise((resolve, reject) => {
if (reset) {
this.reset();
}
this.init(program);
while (this.hasNext) {
if (onTick) {
onTick();
}
this.stepInto();
}
resolve(this.output);
});
}
/**
* Resets the interpreter to default state
* @public */
reset() {
this.program = function () {
let program = [];
for (let i = 0; i < 25; i++) {
program.push(new Array(80).fill(" "));
}
return program;
}();
this.stack = [];
this.output = '';
this.x = 0;
this.y = 0;
this.right();
this.stringMode = false;
}
}
try {
module.exports = Befunge93;
} catch (Error) {
}
},{}],3:[function(require,module,exports){
/*!
* jQuery JavaScript Library v3.3.1
* https://jquery.com/
*
* Includes Sizzle.js
* https://sizzlejs.com/
*
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2018-01-20T17:24Z
*/
( function( global, factory ) {
"use strict";
if ( typeof module === "object" && typeof module.exports === "object" ) {
// For CommonJS and CommonJS-like environments where a proper `window`
// is present, execute the factory and get jQuery.
// For environments that do not have a `window` with a `document`
// (such as Node.js), expose a factory as module.exports.
// This accentuates the need for the creation of a real `window`.
// e.g. var jQuery = require("jquery")(window);
// See ticket #14549 for more info.
module.exports = global.document ?
factory( global, true ) :
function( w ) {
if ( !w.document ) {
throw new Error( "jQuery requires a window with a document" );
}
return factory( w );
};
} else {
factory( global );
}
// Pass this if window is not defined yet
} )( typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
// Edge <= 12 - 13+, Firefox <=18 - 45+, IE 10 - 11, Safari 5.1 - 9+, iOS 6 - 9.1
// throw exceptions when non-strict code (e.g., ASP.NET 4.5) accesses strict mode
// arguments.callee.caller (trac-13335). But as of jQuery 3.0 (2016), strict mode should be common
// enough that all such attempts are guarded in a try block.
"use strict";
var arr = [];
var document = window.document;
var getProto = Object.getPrototypeOf;
var slice = arr.slice;
var concat = arr.concat;
var push = arr.push;
var indexOf = arr.indexOf;
var class2type = {};
var toString = class2type.toString;
var hasOwn = class2type.hasOwnProperty;
var fnToString = hasOwn.toString;
var ObjectFunctionString = fnToString.call( Object );
var support = {};
var isFunction = function isFunction( obj ) {
// Support: Chrome <=57, Firefox <=52
// In some browsers, typeof returns "function" for HTML <object> elements
// (i.e., `typeof document.createElement( "object" ) === "function"`).
// We don't want to classify *any* DOM node as a function.
return typeof obj === "function" && typeof obj.nodeType !== "number";
};
var isWindow = function isWindow( obj ) {
return obj != null && obj === obj.window;
};
var preservedScriptAttributes = {
type: true,
src: true,
noModule: true
};
function DOMEval( code, doc, node ) {
doc = doc || document;
var i,
script = doc.createElement( "script" );
script.text = code;
if ( node ) {
for ( i in preservedScriptAttributes ) {
if ( node[ i ] ) {
script[ i ] = node[ i ];
}
}
}
doc.head.appendChild( script ).parentNode.removeChild( script );
}
function toType( obj ) {
if ( obj == null ) {
return obj + "";
}
// Support: Android <=2.3 only (functionish RegExp)
return typeof obj === "object" || typeof obj === "function" ?
class2type[ toString.call( obj ) ] || "object" :
typeof obj;
}
/* global Symbol */
// Defining this global in .eslintrc.json would create a danger of using the global
// unguarded in another place, it seems safer to define global only for this module
var
version = "3.3.1",
// Define a local copy of jQuery
jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
// Need init if jQuery is called (just allow error to be thrown if not included)
return new jQuery.fn.init( selector, context );
},
// Support: Android <=4.0 only
// Make sure we trim BOM and NBSP
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
jQuery.fn = jQuery.prototype = {
// The current version of jQuery being used
jquery: version,
constructor: jQuery,
// The default length of a jQuery object is 0
length: 0,
toArray: function() {
return slice.call( this );
},
// Get the Nth element in the matched element set OR
// Get the whole matched element set as a clean array
get: function( num ) {
// Return all the elements in a clean array
if ( num == null ) {
return slice.call( this );
}
// Return just the one element from the set
return num < 0 ? this[ num + this.length ] : this[ num ];
},
// Take an array of elements and push it onto the stack
// (returning the new matched element set)
pushStack: function( elems ) {
// Build a new jQuery matched element set
var ret = jQuery.merge( this.constructor(), elems );
// Add the old object onto the stack (as a reference)
ret.prevObject = this;
// Return the newly-formed element set
return ret;