![](/img/trans.png)
[英]Chrome Extension not loading/ code environment not selectable in Inspector/ Dev tools
[英]Why is Chrome Dev Tools inspector showing different values than in code?
一張圖片勝過千言萬語。 也許我累了我不知道,但這讓我陷入了某種原因並且沒有任何意義。 誰能指出我正確的方向?
>右鍵單擊圖像並在新選項卡中打開
/**
* @file maestro.class.js
*
* @external $M Main Maestro Object
* @external $M.Core Maestro Core Object
*/
/**
* A modified version of class.js to cater to static inheritance and deep
* object cloning. Based almost completely on class.js (Javascript MVC --
* Justin Meyer, Brian Moschel, Michael Mayer and others)
* (http://javascriptmvc.com/contribute.html)
*
* - Some portions adapted from Prototype JavaScript framework, version 1.6.0.1 (c) 2005-2007 Sam Stephenson
* - Some portions extracted from jQuery 1.7
* - String utilities methods removed and added to String prototype. Documentation
* added and making code Closure Compiler Advanced Safe by Andrew Donelson.
*
* Class system for javascript
*
* Setup method will be called prior to any init -- nice if you want to do things without needing the
* users to call _super in the init, as well as for normalizing parameters.
*
* @class Class
* @expose
* @namespace Class
* @memberof Core
* Advanced Optimization Compliant
*/
(function (m$)
{
var
/**
* I have dropped this code for production, But it's bothering as to why
* this is happening and I would like to get it figured out.
*
* @property {Object} regs
* @expose
*/
regs = {
'undHash':/_|-/,
'colons':/::/,
'words':/([A-Z]+)([A-Z][a-z])/g,
'lowUp':/([a-z\d])([A-Z])/g,
'dash':/([a-z\d])([A-Z])/g,
'replacer':/\{([^\}]+)\}/g,
'dot':/\./
},
/**
* @method getNext
* @expose
* @param {*} current
* @param {string} nextPart
* @param {boolean} add
* @returns {*}
*/
getNext = function(current, nextPart, add)
{
return current[nextPart] || ( add && (current[nextPart] = {}) );
},
/**
* Returns true if the given parameter is either a function or object
*
* @method isContainer
* @expose
* @param {*} current
* @returns {*}
*/
isContainer=function (current)
{
var type = typeof current;
return type && ( type == 'function' || type == 'object' );
},
/**
* Gets an object from a string.
*
* @method getObject
* @expose
* @param {String} name the name of the object to look for
* @param {Array} [roots] an array of root objects to look for the name
* @param {Boolean} [add] true to add missing objects to
* the path. false to remove found properties. undefined to
* not modify the root object
* @returns {String}
*/
getObject=function (objectName, roots, add)
{
//Production version:
//var parts = objectName ? objectName.split(/\./) : [],
var parts = objectName ? objectName.split(regs.dot) : [],
length = parts.length,
currents = m$.isArray(roots) ? roots : [roots || window],
current,
ret,
i,
c = 0,
type;
if (length == 0)
{
return currents[0];
}
while (current = currents[c++])
{
for (i = 0; i < length - 1 && m$.isContainer(current); i++)
{
current = m$.getNext(current, parts[i], add);
}
if (m$.isContainer(current))
{
ret = m$.getNext(current, parts[i], add);
if (ret !== undefined)
{
if (add === false)
{
delete current[parts[i]];
}
return ret;
}
}
}
};
//This is just trying to get it to save the names correctly.
//not really wanted. and not working anyway.
m$.regs=regs;
m$.getNext = getNext;
m$.isContainer = isContainer;
m$.getObject = getObject;
})(M$['Core']);
使用閉包編譯器進行最小化,進行高級優化:
//So why did everything get renamed? Noot only was expose used,
//but I manually accessed the objects methods and property.
(function(b){
var h={undHash:/_|-/,colons:/::/,words:/([A-Z]+)([A-Z][a-z])/g,lowUp:/([a-z\d])([A-Z])/g,dash:/([a-z\d])([A-Z])/g,replacer:/\{([^\}]+)\}/g,dot:/\./};
b.e=h;
b.a=function(a,b,f){return a[b]||f&&(a[b]={})};
b.b=function(a){return(a=typeof a)&&("function"==a||"object"==a)};
b.d=function(a,d,f){a=a?a.split(h.c):[];
var k=a.length;
d=b.isArray(d)?d:[d||window];
var c,g,e,l=0;if(0==k)return d[0];
for(;c=d[l++];){for(e=0;e<k-1&&b.b(c);e++)c=b.a(c,a[e],f);
if(b.b(c)&&(g=b.a(c,a[e],f),void 0!==g))return!1===f&&delete c[a[e]],g}}
})(M$.Core);
我真的希望你只是復制粘貼完整的文本(如果不在這里粘貼在pastebin或jsfiddle中),因為如果我不得不點擊圖片,記住我看到的內容,點擊此窗口並開始輸入,就更難回答,點擊圖片提醒自己,點擊此窗口繼續輸入...點擊圖片,以確保等。
無論如何,神秘位不是f
改變J
或h
改變J
但G
改變J
和regs
變化J
。
如果您查看下面的行,則只需指定變量f
和h
:
a.G = f;
從那時起f
就不再使用了。 現在,考慮到這,我會認為在某些時候aG
或a.regs
將被分配到Core.J
。 我進一步要假定非封閉編譯的代碼實際上是分配a.regs
到Core.regs
但關閉編譯器編譯Core.regs
到Core.J
和a.regs
成aG
。
在其余的代碼搜索包含的值是如何a
被分配給Core
,你就會有你的答案。
如果要強制關閉導出某些內容,則需要安全地替換名稱。 全局變量無法安全替換,因為它們可能被頁面中包含的另一個js文件使用。 因此,如果您希望保留regs
,則通過刪除var
使其成為全局。
或者,根據您的需要明確指出a
是全局的還是Core
或M$
是全局的。
清除緩存或按ctrl + F5重新加載頁面。
好的,這是其他任何試圖使其代碼Closure Compiler Advanced Optimization Safe的工作獨立代碼。 請記住,Code和JSDOC / Closure評論是必需的。 我使用了額外的@expose標簽,但這並沒有傷害。
原始來源::
/**
* A modified version of class.js to cater to static inheritance and deep
* object cloning. Based almost completely on class.js (Javascript MVC --
* Justin Meyer, Brian Moschel, Michael Mayer and others)
* (http://javascriptmvc.com/contribute.html)
*
* - Some portions adapted from Prototype JavaScript framework, version 1.6.0.1 (c) 2005-2007 Sam Stephenson
* - Some portions extracted from jQuery 1.7
* - String utilities methods removed and added to String prototype. Documentation
* added and making code Closure Compiler Advanced Safe by Andrew Donelson.
*
* Class system for javascript
*
* Setup method will be called prior to any init -- nice if you want to do things without needing the
* users to call _super in the init, as well as for normalizing parameters.
*
* @class Class
* @expose
* @namespace Class
* @memberof Core
* Advanced Optimization Compliant
*/
(function (m$)
{
/**
* Some stand regular expressions used by the internal string prototypes
* to handle correct naming.
*
* @property {Object} regs
* @expose
*/
m$['regs'] = {
'undHash':/_|-/,
'colons':/::/,
'words':/([A-Z]+)([A-Z][a-z])/g,
'lowUp':/([a-z\d])([A-Z])/g,
'dash':/([a-z\d])([A-Z])/g,
'replacer':/\{([^\}]+)\}/g,
'dot':/\./
},
/**
* @method getNext
* @expose
* @param {*} current
* @param {string} nextPart
* @param {boolean} add
* @returns {*}
*/
m$['getNext'] = function(current, nextPart, add)
{
return current[nextPart] || ( add && (current[nextPart] = {}) );
},
/**
* Returns true if the given parameter is either a function or object
*
* @method isContainer
* @expose
* @param {*} current
* @returns {*}
*/
m$['isContainer'] = function (current)
{
var type = typeof current;
return type && ( type == 'function' || type == 'object' );
},
/**
* Gets an object from a string.
*
* @method getObject
* @expose
* @param {String} name the name of the object to look for
* @param {Array} [roots] an array of root objects to look for the name
* @param {Boolean} [add] true to add missing objects to
* the path. false to remove found properties. undefined to
* not modify the root object
* @returns {String}
*/
m$['getObject'] = function (objectName, roots, add)
{
var parts = objectName ? objectName.split(regs['dot']) : [],
length = parts.length,
currents = m$.isArray(roots) ? roots : [roots || window],
current,
ret,
i,
c = 0,
type;
if (length == 0)
{
return currents[0];
}
while (current = currents[c++])
{
for (i = 0; i < length - 1 && m$.isContainer(current); i++)
{
current = m$.getNext(current, parts[i], add);
}
if (m$.isContainer(current))
{
ret = m$.getNext(current, parts[i], add);
if (ret !== undefined)
{
if (add === false)
{
delete current[parts[i]];
}
return ret;
}
}
}
}
})(M$['Core']);
這里是高級優化最小化代碼清理了一點易讀性::
(function(b){
b.regs={
undHash:/_|-/,
colons:/::/,
words:/([A-Z]+)([A-Z][a-z])/g,
lowUp:/([a-z\d])([A-Z])/g,
dash:/([a-z\d])([A-Z])/g,
replacer:/\{([^\}]+)\}/g,
dot:/\./
};
b.getNext=function(a,b,f){return a[b]||f&&(a[b]={})};
b.isContainer=function(a){return(a=typeof a)&&("function"==a||"object"==a)};
b.getObject=function(a,d,f){a=a?a.split(regs.dot):[];
var h=a.length;
d=b.isArray(d)?d:[d||window];
var c,g,e,k=0;if(0==h)return d[0];
for(;c=d[k++];){for(e=0;e<h-1&&b.b(c);e++)c=b.a(c,a[e],f);
if(b.b(c)&&(g=b.a(c,a[e],f),void 0!==g))return!1===f&&delete c[a[e]],g}}
})(M$.Core); // 584 Bytes
簡單優化最小化代碼清理了一點易讀性::
(function(b){
b.regs={
undHash:/_|-/,
colons:/::/,
words:/([A-Z]+)([A-Z][a-z])/g,
lowUp:/([a-z\d])([A-Z])/g,
dash:/([a-z\d])([A-Z])/g,
replacer:/\{([^\}]+)\}/g,
dot:/\./
};
b.getNext=function(a,b,f){return a[b]||f&&(a[b]={})};
b.isContainer=function(a){return(a=typeof a)&&("function"==a||"object"==a)};
b.getObject=function(a,d,f){a=a?a.split(regs.dot):[];
var h=a.length;d=b.isArray(d)?d:[d||window];
var c,g,e,k=0;
if(0==h)return d[0];
for(;c=d[k++];){for(e=0;e<h-1&&b.isContainer(c);e++)c=b.getNext(c,a[e],f);
if(b.isContainer(c)&&(g=b.getNext(c,a[e],f),void 0!==g))return!1===f&&delete c[a[e]],g}}
})(M$.Core); //616 bytes
是的,如果:您提前計划結構並使用正確的Closures,並將所有內部幫助器或實用程序方法添加到主閉包內的另一個閉包中。 這樣你就不會弄亂你的主要對象。
否:如果:標准無組織代碼。 這根本沒有錯,但是不值得浪費你的時間來進行高級優化。
好吧,讓我知道你的想法。 並感謝您的投入和幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.