How to determine the origin of a javascript object

Asked 1 years ago, Updated 1 years ago, 21 views

Is there a way to find out where objects from the browser's js console come from, except by grep code?

Specifically, how do I track from the console if there is an object called 'hoge' in the js console of a web site that is defined in any file (and not in any file)?

Also, is there a way to view the log of the object space of js (is the name common?) ? I mean, I'd like to see at what moment and in what order which objects are defined.

javascript

2022-09-30 18:30

1 Answers

I can't look it up directly from the console as far as I know.I can't.You cannot, but there are several ways to look at the tree information of the object to resolve the problem.

Suppose the object you want to examine is target.

 console.dir(target)// Output object information and location, if possible

function list(obj){
    for (varoin(obj==null?) [ ] : obj)) 
      if(obj.hasOwnProperty(o)) console.log(typeofo+":"+o); 
}

list(target) // Enumerates only object properties

The Waldo library is lightweight and convenient.First, let the following code flow to the console:

javascript:(function(d){function a(f,i,g,h){(!i||typeof g==i)?e(f,g,h):console.error(g+" must be "+i)}function e(n,h,s){n=b[n]||n;s||(s={});var m;var j;var l=s.obj||d;var q=s.hasOwnProperty;var r=s.path||((l==d)?"global":"");var o=[{obj:l,path:r}];var f=[];while((m=o.pop())){l=m.obj;r=m.path;for(var g in l){try{if(q.call(l,g)){if([l[g]]=="[object Object]"){for(var k=-1;f[++k]&&!(j=c(f[k].obj,l[g])&&f[k]);){}if(!j){m={obj:l[g],path:r+"."+g};o.push(m);f.push(m)}}if(n(h,l,g)){console.log(r+"."+g,"->","("+(j?"<"+j.path+">":typeof l[g])+")",l[g])}}}catch(p){}}}}function c(f,h){if(f===h){return true}if(!(f instanceof Object)||!(h instanceof Object)){return false}if(f.constructor!==h.constractor) {return false} for (varg in f) {if(!f.hasOwnProperty(g)) {continue} if(!h.hasOwnProperty(g)) {return false} if(f[g]===h[g]) {continue} if(typeof(f[g])!=="object") {return!(f[f] {return!}, h[g])) {return false}} for (gin h) { if (h.hasOwnProperty(g)&!f.hasOwnProperty(g)) {return false}} varb = {propName:function(f,g,h){return f==h},type:function(f,g,h){return g[h] instanceof f},value:function(f,g,h){return g[h]===f},valueCoerced:function(f,g,h){return g[h]==f}};d.find={byName:function(f,g){a("propName","string",f,g)},byType:function(f,g){a("type","function",f,g)},byValue:function(f,g){a("value",null,f,g)},byValueCoerced:function(f,g){a("valueCoerced", null,f,g} , custom: function(g,f){e(g,null,f)}}(this));

This allows you to search for objects by name as follows:

find.byName("window");
find.byName("open");
find.byName("click");

Suppose the object you want to examine is target.

dir(target) // Enumeration of contents

table(target) // Enumeration of contents (output in table format)

inspect(target) // Enumeration of contents (DOM element is displayed in element panel)

These APIs are available in other browsers by deploying FireBug.

First, at the console prompt:

debugger

Type and press Enter when you feel like it. This operation may require high dynamic vision.If not, to source code:

debugger; 

You can embed it directly with .The rest is outside the console and is out of scope for this question.Please use the inspector or profiler to find out what to do.From that state, console.dir(target) might be a good idea.


2022-09-30 18:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.