1 | var util = require('util')
|
2 |
|
3 | exports.extend = function(){
|
4 | var obj = arguments[0]
|
5 | var obj2, i, k
|
6 | for (i = 1; i < arguments.length; i++) {
|
7 | obj2 = arguments[i]
|
8 | if (obj2) {
|
9 | for (k in obj2) {
|
10 | if (obj2.hasOwnProperty(k)) {
|
11 | obj[k] = obj2[k]
|
12 | }
|
13 | }
|
14 | }
|
15 | }
|
16 | return obj
|
17 | }
|
18 |
|
19 | exports.shallowCopy = function(obj){
|
20 | var copy
|
21 | if (util.isArray(obj)) {
|
22 | copy = obj.slice(0)
|
23 | }
|
24 | else {
|
25 | copy = exports.extend({}, obj)
|
26 | }
|
27 | return copy
|
28 | }
|
29 |
|
30 | exports.isFunction = function(obj){
|
31 | return (typeof obj === 'function')
|
32 | }
|
33 |
|
34 | exports.isFobject = function(obj){
|
35 | if (obj) {
|
36 | var type = (typeof obj)
|
37 | if (type === 'function') { return true }
|
38 | if (type === 'object') {
|
39 | type = Object.prototype.toString.call(obj).match(/\w+/g)[1].toLowerCase()
|
40 | return !(type === 'array' || type === 'boolean' || type === 'date' || type === 'number' || type === 'regexp' || type === 'string')
|
41 | }
|
42 | }
|
43 | return false
|
44 | }
|