Skip to content
Browse files

Fix isObject regex; add console.js

  • Loading branch information...
1 parent f3d1dcd commit cb8325f9975b7bc50f664397e2bdc025abe39f7b Juriy Zaytsev committed Feb 22, 2009
Showing with 39 additions and 2 deletions.
  1. +37 −0 console.js
  2. +2 −2 object.extensions.js
View
37 console.js
@@ -0,0 +1,37 @@
+(function(global){
+
+ var global = this;
+
+ var methods = (function(){
+ var timeTable = { };
+ function time(id) {
+ timeTable['_' + id] = new Date();
+ }
+ function timeEnd(id) {
+ var _id = '_' + id;
+ if (timeTable[_id]) {
+ console.log(id + ': ' + (new Date() - timeTable[_id]) + 'ms');
+ delete timeTable[_id];
+ }
+ }
+ return {
+ time: time,
+ timeEnd: timeEnd
+ }
+ })();
+
+ if (!global.console) {
+ global.console = { }
+ }
+ if (!global.console.log) {
+ global.console.log = (global.opera && global.opera.postError)
+ ? global.opera.postError
+ : function(){ }
+ }
+ if (!global.console.time) {
+ global.console.time = methods.time;
+ }
+ if (!global.console.timeEnd) {
+ global.console.timeEnd = methods.timeEnd;
+ }
+})();
View
4 object.extensions.js
@@ -118,7 +118,7 @@ Object.isNodeList = function(object) {
};
Object.isPrimitive = function(o) {
- return (o == null || /number|string|boolean/.test(typeof o));
+ return (o == null || /^(number|string|boolean)$/.test(typeof o));
};
Object.hasMagicLength = function(o) {
@@ -141,7 +141,7 @@ Object.hasMagicLength = function(o) {
Object.create = (function(){
function F(){};
function isObject(o) {
- return !!o && !/undefined|boolean|string|number/.test(typeof o);
+ return (o != null && !/^(boolean|string|number)$/.test(typeof o));
}
return function(parent, properties) {
if (!isObject(parent) || !isObject(properties)) {

0 comments on commit cb8325f

Please sign in to comment.
Something went wrong with that request. Please try again.