面向对象

面向对象的特征有哪些方面

封装

最常见的是把属性私有化封装在一个类里面,只能通过方法去访问

get.classList.add("active", "active-current"); let parent = target.parentNode; while (!parent.matches(".toc")) { if (parent.matches("li")) parent.classList.add("active"); parent = parent.parentNode; } } function findIndex(entries) { let index = 0; let entry = entries[index]; if (entry.boundingClientRect.top > 0) { index = sections.indexOf(entry.target); return index === 0 ? 0 : index - 1; } for (; index < entries.length; index++) { if (entries[index].boundingClientRect.top <= 0) { entry = entries[index]; } else { return sections.indexOf(entry.target); } } return sections.indexOf(entry.target); } function createIntersectionObserver(marginTop) { marginTop = Math.floor(marginTop + 10000); let intersectionObserver = new IntersectionObserver( (entries, observe) => { let scrollHeight = document.documentElement.scrollHeight + 100; if (scrollHeight > marginTop) { observe.disconnect(); createIntersectionObserver(scrollHeight); return; } let index = findIndex(entries); activateNavByIndex(navItems[index]); }, { rootMargin: marginTop + "px 0px -100% 0px", threshold: 0, } ); sections.forEach((element) => { element && intersectionObserver.observe(element); }); } createIntersectionObserver(document.documentElement.scrollHeight); } document.addEventListener("DOMContentLoaded", listennSidebarTOC); document.addEventListener("pjax:success", listennSidebarTOC);;(adsbygoogle=window.adsbygoogle||[]).push({});var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?2cd1dc193190f18fed292accb735c684";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}();var pjax; document.addEventListener('DOMContentLoaded', function () { pjax = new Pjax({ elements: 'a[href]:not([href^="#"]):not([href="javascript:void(0)"]):not([pjax-fancybox])', selectors: [ "title", "#l_cover", "#pjax-container", "#pjax-header-nav-list" ], cacheBust: false, // url 地址追加时间戳,用以避免浏览器缓存 timeout: 5000 }); }); document.addEventListener('pjax:send', function (e) { //window.stop(); // 相当于点击了浏览器的停止按钮 try { var currentUrl = window.location.pathname; var targetUrl = e.triggerElement.href; var banUrl = [""]; if (banUrl[0] != "") { banUrl.forEach(item => { if(currentUrl.indexOf(item) != -1 || targetUrl.indexOf(item) != -1) { window.location.href = targetUrl; } }); } } catch (error) {} window.subData = null; // 移除标题(用于一二级导航栏切换处) if (typeof $.fancybox != "undefined") { $.fancybox.close(); // 关闭弹窗 } volantis.$switcher.removeClass('active'); // 关闭移动端激活的搜索框 volantis.$header.removeClass('z_search-open'); // 关闭移动端激活的搜索框 volantis.$wrapper.removeClass('sub'); // 跳转页面时关闭二级导航 // 解绑事件 避免重复监听 volantis.$topBtn.unbind('click'); $('.menu a').unbind('click'); $(window).unbind('resize'); $(window).unbind('scroll'); $(document).unbind('scroll'); $(document).unbind('click'); $('body').unbind('click'); }); document.addEventListener('pjax:complete', function () { // 关于百度统计对 SPA 页面的处理: // 方案一:百度统计>管理>单页应用设置中,打开开启按钮即可对SPA进行统计。 https://tongji.baidu.com/web/help/article?id=324 // 方案二:取消注释下列代码。 https://tongji.baidu.com/web/help/article?id=235 // // 关于谷歌统计对 SPA 页面的处理: // 当应用以动态方式加载内容并更新地址栏中的网址时,也应该更新通过 gtag.js 存储的网页网址。 // https://developers.google.cn/analytics/devguides/collection/gtagjs/single-page-applications?hl=zh-cn $('.nav-main').find('.list-v').not('.menu-phone').removeAttr("style",""); // 移除小尾巴的移除 $('.menu-phone.list-v').removeAttr("style",""); // 移除小尾巴的移除 $('script[data-pjax], .pjax-reload script').each(function () { $(this).parent().append($(this).remove()); }); try{ if (typeof $.fancybox == "undefined") { SCload_fancybox(); } else { pjax_fancybox(); } Pjax_backstretch() document.querySelectorAll('pre code').forEach((block) => { hljs.highlightBlock(block); }); pjax_scrollrebeal(); if (typeof MiniValine == "undefined") { load_minivaline(); } else { pjax_minivaline(); } } catch (e) { console.log(e); } }); document.addEventListener('pjax:error', function (e) { window.location.href = e.triggerElement.href; });