You need to do the following:
- Get all the proper property names for each object.
- Filter the functions.
- Create a union of both sets.
The first two steps can be combined into one function:
function getOwnFunctionNames(object) { var properties = Object.getOwnPropertyNames(object); var length = properties.length; var functions = []; for (var i = 0; i < length; i++) { var property = properties[i]; if (typeof object[property] === "function") functions.push(property); } return functions; }
Next, you need to find the union of many functions from two objects:
function getConflictingFunctionNames(object1, object2) { var functions1 = getOwnFunctionNames(object1); var functions2 = getOwnFunctionNames(object2); var length = functions1.length; var functions = []; for (var i = 0; i < length; i++) { var functionName = functions1[i]; if (functions2.indexOf(functionName) >= 0) functions.push(functionName); } return functions; }
Now you can do whatever you want with these functions.
See the demo here: http://jsfiddle.net/gVCNd/
source share