-6

请参阅:JavaScript 对象文字符号与普通函数和性能影响?


我正在考虑将我的函数和相关数据转换为对象表示法。性能成本是多少(如果有的话?)

我目前对我的函数使用一种命名约定,它是结构化的并反映了将成为对象的内容。因此,对象字面量表示法并没有真正为函数的目的添加太多说明。

无论如何,我计划转换为适当的对象。通过这样做,我会在执行速度方面获得或失去任何东西吗?(也许是因为取消引用?)

我正在考虑将以下函数和相关数据转换为对象表示法。我最终会得到以下对象:

oFilter
oMenuImage
oTimer
oWindow
oMouseEvent
oElement
oLayout
oTooltip

因此,在查看对象 oFilter 下方的第一个函数时,可能包含以下函数:

ControlCreate
Store
Restore
ResetThenAnimate
Animate
Spin
SetRotation
Resize
SlideStyleToggle
Get
Set
Enable
Play

可以找到完整的网页和脚本: HEREHERE
但留在主页上,其余部分不会更新。

该网站是一个相当大的教育项目。在不久的将来,我将学习对象文字符号(我喜欢)和框架的使用。这是现有函数的列表(它很大):查找所有“函数 fn”、隐藏、正则表达式、查找结果 2、当前文档

function fnFilterControlCreate(filterPlayAll, startIndex, endIndex,
      MdmPtPageJava.js(123):        function fnFilterStore(oObj, oObjImage, filterIndex) {
      MdmPtPageJava.js(133):        function fnFilterRestore(oObj, oObjImage, filterIndex) {
      MdmPtPageJava.js(152):        function fnFilterResetThenAnimate(oObj, oObjImage, filterIndex) {
      MdmPtPageJava.js(179):        function fnFilterAnimate(oObj, oObjImage, filterIndex, flMultiplier) {
      MdmPtPageJava.js(201):        function fnFilterSpin(oObj, oObjImage, filterIndex, IsImageLarge) {
      MdmPtPageJava.js(242):        function fnFilterSetRotation(oObj, oObjImage, filterIndex, deg) {
      MdmPtPageJava.js(259):        function fnFilterResize(oObj, oObjImage, filterIndex, flMultiplier, IsImageLarge, imgWidthPassed, imgHeightPassed, DoHeight) {
      MdmPtPageJava.js(331):        function fnFilterSlideStyleToggle(oObj, oObjImage, filterIndex) {
      MdmPtPageJava.js(357):        function fnFilterGet(filterPlayAll, startIndex, endIndex,
      MdmPtPageJava.js(446):        function fnFilterSet(filterPlayAll, startIndex, endIndex,
      MdmPtPageJava.js(463):        function fnFilterEnable(filterPlayAll, startIndex, endIndex,
      MdmPtPageJava.js(494):        function fnFilterApply(filterPlayAll, startIndex, endIndex,
      MdmPtPageJava.js(529):        function fnFilterPlay(playDirection, timerMethod, IsImageLarge,
      MdmPtPageJava.js(568):        function fnFilterStop(filterPlayAll, startIndex, endIndex,
      MdmPtPageJava.js(628):        function fnFilterGetByIndex(
      MdmPtPageJava.js(991):        function fnFilterGetByTagName(filterTagName) {
      MdmPtPageJava.js(1002):        function fnFilterGetRandom(filterClassSingle, filterClassDynamic, filterIndex,
      MdmPtPageJava.js(1022):        function fnFilterTimingGetByIndex() {
      MdmPtPageJava.js(1029):        function fnFilterTimingGetRandom() {
      MdmPtPageJava.js(1037):        function fnStyleBackgroundToggle(oObj, oObjImage, filterIndex) {
      MdmPtPageJava.js(1058):        function fnMenuImgAnimationPlayFirst(playDirection, timerMethod, IsImageLarge, oObjNextParent, oObjNextImage, oObjNext, oObjNextLarge,
      MdmPtPageJava.js(1076):        function fnMenuImgAnimationPlayNext(playDirection, timerMethod, IsImageLarge, oObjNextParent, oObjNextImage, oObjNext, oObjNextLarge,
      MdmPtPageJava.js(1095):        function fnMenuImgAnimationPlayAgain(playDirection, timerMethod, IsImageLarge, oObjNextParent, oObjNextImage, oObjNext, oObjNextLarge,
      MdmPtPageJava.js(1110):        function fnMenuImgAnimationPlay(playDirection, timerMethod, IsImageLarge, oObjNextParent, oObjNextImage, oObjNext, oObjNextLarge,
      MdmPtPageJava.js(1422):        function fnTimerStart(timerType, timerGroup, timerId, IsImageLarge,
      MdmPtPageJava.js(1548):        function fnTimerSet(timerType, timerGroup, timerId, IsImageLarge,
      MdmPtPageJava.js(1629):        function fnTimerFilterStart(playDirection, timerMethod, IsImageLarge,
      MdmPtPageJava.js(1688):        function fnTimerMoveStart(playDirection, timerMethod, IsImageLarge,
      MdmPtPageJava.js(1794):        function fnTimerFilterStepDoGroup(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(1910):        function fnTimerFilterStepDoItem(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(2041):        function fnTimerMoveStepDoGroup(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(2151):        function fnTimerMoveStepDoItem(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(2460):        function fnTimerSetDisplayed(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(2505):        function fnTimerStop(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(2536):        function fnTimerMoveTest(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(2558):        function fnTimerObjectSet(playDirection, timerMethod, IsImageLarge, oObjNextParent, oObjNextImage, oObjNext, oObjNextLarge, iImageSize, oObjGroupIndex, oObjGroupImageIndex, oObjLocked, IgnoreLock) {
      MdmPtPageJava.js(2599):        function fnTimerDeactivate(timerType, timerGroup, timerId, IsImageLarge, timerDoRoot) {
      MdmPtPageJava.js(2636):        function fnTimerDefaults(timerType, timerGroup, timerId, IsImageLarge,
      MdmPtPageJava.js(2899):        function fnTimerBusy(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(2921):        function fnTimerObjectExists(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(2930):        function fnTimerKeyText(playDirection, timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(2942):        function fnTimerIntervalText(timerType, timerGroup, timerId, IsImageLarge, UseRootKey) {
      MdmPtPageJava.js(2957):        function fnTimerRootKeyText(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(3001):        function fnTimerGetElapsed(timerType, timerGroup, timerId, IsImageLarge) {
      MdmPtPageJava.js(3058):        function fnBodyImagesHtmlBuild() {
      MdmPtPageJava.js(3075):        function fnMenuImgHtmlBuild() {
      MdmPtPageJava.js(3955):        function fnlayoutContainerHeightGetAll() {
      MdmPtPageJava.js(3987):        function fnWindowResize() {
      MdmPtPageJava.js(4324):        function fnWindowBlockWidthAjust()
      MdmPtPageJava.js(4331):        function fnWindowBlockWidth()
      MdmPtPageJava.js(4454):        function fnWindowClientWidth() {
      MdmPtPageJava.js(4500):        function fnWindowSessionLoad() {
      MdmPtPageJava.js(4510):        function fnWindowSessionSave() {
      MdmPtPageJava.js(4525):        function fnWindowCookieLoad() {
      MdmPtPageJava.js(4533):        function fnWindowCookieSave() {
      MdmPtPageJava.js(4541):        function fnWindowCookieBuild() {
      MdmPtPageJava.js(4555):        function fnDocumentLoad() {
      MdmPtPageJava.js(4575):        function fnDocumentLoadInit() {
      MdmPtPageJava.js(4615):        function fnMathNumberRandomGetByRange(filterRangeLow, filterRangeHigh, filterRealFlag) {
      MdmPtPageJava.js(4626):        function fnFontSizeIncrease() {
      MdmPtPageJava.js(4632):        function fnFontSizeDecrease() {
      MdmPtPageJava.js(4643):        function fnDebugStart(debugOption, debugMessage) {
      MdmPtPageJava.js(4680):        function fnMouseEventOverImg(menuImage) {
      MdmPtPageJava.js(4704):        function fnMouseEventOutImg(menuImage) {
      MdmPtPageJava.js(4720):        function fnMouseEventClickImg(menuImage) {
      MdmPtPageJava.js(4758):        function fnWindowPopupOpen() {
      MdmPtPageJava.js(4772):        function fnElementObjectBlockCount() {
      MdmPtPageJava.js(4803):        function fnElementObjectContainerCreate() {
      MdmPtPageJava.js(4836):        function fnElementObjectCreate() {
      MdmPtPageJava.js(5001):        function fnElementGetRef(elementObject, elementObjectId, elementName) {
      MdmPtPageJava.js(5016):        function fnElementGetRefFromElement(element, elementId, elementName, elementSource) {
      MdmPtPageJava.js(5048):        function fnElementCreate(element, elementLayoutFirst) {
      MdmPtPageJava.js(5064):        function fnElementCopy(element, elementLayoutFirst, elementSource, elementStyleDisplay) {
      MdmPtPageJava.js(5111):        function fnElementFindInElement(
      MdmPtPageJava.js(5183):        function fnElementEventsCopy(elementObject, elementSourceObject, elementObjectId, elementSourceObjectId) {
      MdmPtPageJava.js(5260):        function fnElementBreakSet(element, elementId, elementLayoutFirst, elementStyleDisplay, elementStyleVisibility, elsementStyleClear) {
      MdmPtPageJava.js(5328):        function fnConsoleEventLog(mouseEventCurr, mouseEventType, mouseEventObject, mouseEventCurrRootObj,
      MdmPtPageJava.js(5495):        function fnTextReplace(text, stringFind, stringReplace) {
      MdmPtPageJava.js(5506):        function fnWindowError(errorMsg, errorUrl, errorLineNum) {
      MdmPtPageJava.js(5550):        function fnWindowErrorDebug(UseDebugger, errorMsg, errorUrl, errorLineNum) {
      MdmPtPageJava.js(5624):        function fnBrowserGetVs() {
      MdmPtPageJava.js(5635):        function fnBodyConsoleToggle(ConsoleBlock) {
      MdmPtPageJava.js(5908):        function fnLayoutFontSize(layoutMenuIndex) {
      MdmPtPageJava.js(5923):        function fnLayoutNext(layoutMenuIndex) {
      MdmPtPageJava.js(5936):        function fnLayoutCheck(layoutPrefered) {
      MdmPtPageJava.js(5943):        function fnLayoutRefresh(layoutMenuIndex, IsTemporary) {
      MdmPtPageJava.js(5954):        function fnLayoutSelectByIndex(layoutMenuIndexPassed, IsTemporary)
      MdmPtPageJava.js(6603):        function fnElementPosGet(oObjGroupIndex, oObjIndex, DoScroll, DoBase, element, elementWidthDefault, elementHeightDefault) {
      MdmPtPageJava.js(6617):        function fnElementPosCalculate(element, oObjGroupIndex, oObjIndex) {
      MdmPtPageJava.js(6646):        function fnParseInt(stringToParse) { return parseInt("0" + stringToParse); }
      MdmPtPageJava.js(6651):        function fnLayoutTopMaxGet(DoOffset, DoScroll, DoBase, element)
      MdmPtPageJava.js(6679):        function fnLayoutLeftMaxGet(DoOffset, DoScroll, DoBase, element)
      MdmPtPageJava.js(6707):        function fnLayoutWidthMaxGet(DoOffset, DoScroll, DoBase, element, elementWidthDefault)
      MdmPtPageJava.js(6736):        function fnLayoutHeightMaxGet(DoOffset, DoScroll, DoBase, element, elementHeightDefault)
      MdmPtPageJava.js(6818):        function fnMouseEventAddToElement(eventName, eventFunction, eventFunctionName, eventFunctionArgs, oObj) {
      MdmPtPageJava.js(6860):        // function fnMouseZoomHandler(e) {
      MdmPtPageJava.js(6902):            function fnTooltipShow(e, tooltipSourceElementPassed, tooltipId, tooltipInnerHtml, tooltipWidth) 
      MdmPtPageJava.js(6978):                function fnTooltipPos(e, direction)
      MdmPtPageJava.js(7020):                function fnTooltipFade(e, direction)
      MdmPtPageJava.js(7047):                function fnTooltipFadeIncrement(e, direction, beforeFlag)
      MdmPtPageJava.js(7085):                function fnTooltipHide(e) {
      MdmPtPageJava.js(7099):                function fnTooltipStop(e)
      MdmPtPageJava.js(7117):        function fnElementChangeCss(theClass, element, value)
      MdmPtPageJava.js(7151):        function fnMouseEventHandler(e)
      MdmPtPageJava.js(7404):        function fnMouseEventCurrRootObjSet(mouseEventObjectPassed)
      MdmPtPageJava.js(7422):        function fnMouseEventLastSet(e) {
      MdmPtPageJava.js(7433):        function fnMouseEventCurrSet(e) {
      MdmPtPageJava.js(7481):        function fnMouseEventCheckInvalid() {
      MdmPtPageJava.js(7528):        function fnMenuImgSetLock(IsImageLarge, oObjGroupIndex, oObjGroupImageIndex, oObjLocked, IgnoreLock) {
      MdmPtPageJava.js(7540):        function fnMenuImgHideId(e, IsImageLarge, oObjNextParentId, oObjNextImageId, oObjNextId, oObjGroupIndex, oObjGroupImageIndex, oObjLocked, IgnoreLock) {
      MdmPtPageJava.js(7568):        function fnMenuImgHide(playDirection, IsImageLarge, oObjNextParent, oObjNextImage, oObjNext, oObjNextLarge, oObjGroupIndex, oObjGroupImageIndex, oObjLocked, IgnoreLock) {
      MdmPtPageJava.js(7645):        function fnMenuImgToggleRange(HideImage, HideImageLarge, startIndex, endIndex, IsImageLarge, oObjNextParentId, oObjNextImageId, oObjNextId, iImageSize, oObjGroupIndex, oObjGroupImageIndex, oObjLocked, IgnoreLock) {
      MdmPtPageJava.js(7766):        function fnMenuImgToggle(IsImageLarge, oObjNextParentId, oObjNextImageId, oObjNextId, iImageSize, oObjGroupIndex, oObjGroupImageIndex, oObjLocked, IgnoreLock) {
      MdmPtPageJava.js(7816):        function fnMenuImgLayoutRefresh(layoutActionPassed, startIndex, endIndex, IsImageLarge, oObjGroupIndex, oObjGroupImageIndex, oObjLocked, IgnoreLock) {
      MdmPtPageJava.js(7922):        function fnMenuImgShowIndex(IsImageLarge, oObjNextParent, oObjNextImage, oObjNext, oObjNextLarge, iImageSize, oObjGroupIndex, oObjGroupImageIndex, oObjLocked, IgnoreLock) {
      MdmPtPageJava.js(7935):        function fnMenuImgShowStack(timerMethod, IsImageLarge, oObjNextParentId, oObjNextImageId, oObjNextId, iImageSize, oObjGroupIndex, startIndex, endIndex, oObjLocked, IgnoreLock) {
      MdmPtPageJava.js(8027):        function fnMenuImgShowId(playDirection, timerMethod, IsImageLarge,
      MdmPtPageJava.js(8111):        function fnMenuImgProcess(playDirection, timerMethod, IsImageLarge, oObjNextParent, oObjNextImage, oObjNext, oObjNextLarge, iImageSize, oObjGroupIndex, oObjGroupImageIndex, oObjLocked, IgnoreLock) {
      MdmPtPageJava.js(8691):        function fnElementGet(Id) { return document.getElementById(Id); }
      MdmPtPageJava.js(8696):        function fnMenuObjectSetAll(oObjGroupIndex, oObjIndex) {
      MdmPtPageJava.js(8866):        function fnMenuObjectTextSet(oObjGroupIndex, oObjIndex) {
      MdmPtPageJava.js(8964):        function fnMenuObjectNameSet(oObjGroupIndex, oObjIndex) {
      MdmPtPageJava.js(9065):        function fnMenuObjectIndexSet(oObj, DoIgnoreError) {
      MdmPtPageJava.js(9202):        function fnMenuObjectIndexSetByName(oObj) {
4

1 回答 1

0

正如 TJ Crowder 在“JavaScript 对象文字符号与普通函数和性能影响?”问题的评论中所说的那样。

JS 中的性能问题很棘手,因为引擎差异很大。但如果你指的是问题中的两个选项,答案几乎肯定是否定的。一旦引擎有了函数引用,在两种情况下调用都是一样的,所以我们必须看看引擎是如何获取函数引用的。

在第一个示例中,要调用 foo,引擎必须在执行上下文的绑定对象上查找 foo。在第二个示例中,它必须以相同的方式查找 Baz,然后在 Baz 上查找 foo,这是更多步骤。但我敢打赌,这并没有真正的区别。

于 2013-07-20T13:23:03.980 回答