Permalink
Browse files

Removed custom indexOf method

  • Loading branch information...
1 parent f0ce075 commit 2ffdd84e4e2a522ef4651cd897d8a4949348c842 @wagenet wagenet committed Aug 23, 2011
Showing with 6 additions and 21 deletions.
  1. +6 −21 lib/spade.js
View
@@ -8,7 +8,7 @@
(function() {
-var K, indexOf, Sandbox, Sp, Evaluator, Ep, Loader, Lp, Spade, Tp;
+var K, Sandbox, Sp, Evaluator, Ep, Loader, Lp, Spade, Tp;
// ..........................................................
@@ -17,24 +17,9 @@ var K, indexOf, Sandbox, Sp, Evaluator, Ep, Loader, Lp, Spade, Tp;
K = function() {}; // noop
-if (Array.prototype.indexOf) {
- indexOf = function(ary, obj, fromIndex) {
- return ary.indexOf(obj, fromIndex);
- };
-} else {
- indexOf = function(ary, obj, fromIndex) {
- var len = ary.length, idx;
- fromIndex = fromIndex<0 ? Math.max(0, ary.length+fromIndex) : (fromIndex||0);
- for(idx = fromIndex; idx<len; idx++) {
- if (ary[idx] === obj) return idx;
- }
- return -1;
- };
-}
-
// assume id is already normalized
function packageIdFor(normalizedId) {
- return normalizedId.slice(0, indexOf(normalizedId, '/'));
+ return normalizedId.slice(0, normalizedId.indexOf('/'));
}
function remap(id, contextPkg) {
@@ -43,7 +28,7 @@ function remap(id, contextPkg) {
var packageId = packageIdFor(id);
if (mappings[packageId]) {
- id = mappings[packageId] + id.slice(indexOf(id, '/'));
+ id = mappings[packageId] + id.slice(id.indexOf('/'));
}
return id;
}
@@ -59,7 +44,7 @@ function normalize(id, contextId, contextPkg, _asPackage) {
if (id[id.length-1]==='/') { id = id.slice(0,-1); }
// need to walk if there is a .
- if (indexOf(id, '.')>=0) {
+ if (id.indexOf('.')>=0) {
var parts = contextId && (id.charAt(0) ==='.') ? contextId.split('/') : [],
part, next,
packageName = parts[0],
@@ -77,7 +62,7 @@ function normalize(id, contextId, contextPkg, _asPackage) {
parts.pop(); // get rid of the last path element since it is a module.
while(idx<len) {
- next = indexOf(id, '/', idx);
+ next = id.indexOf('/', idx);
if (next<0) { next = len; }
part = id.slice(idx, next);
if (part==='..') { parts.pop(); }
@@ -100,7 +85,7 @@ function normalize(id, contextId, contextPkg, _asPackage) {
} else if (id[0]==='/') { id = id.slice(1); }
// if we end up with no separators, make this a pkg
- if (indexOf(id, '/')<0) { id = id+(_asPackage ? '/~package' : '/main'); }
+ if (id.indexOf('/')<0) { id = id+(_asPackage ? '/~package' : '/main'); }
// slice separators off begin and end
if (id[0]==='/') { id = id.slice(1); }

0 comments on commit 2ffdd84

Please sign in to comment.