(function() { var canvas = document.getElementById('quakeCanvas'); // Create our Planetary.js planet and set some initial values; // we use several custom plugins, defined at the bottom of the file var planet = planetaryjs.planet(); planet.loadPlugin(autocenter({extraHeight: -120})); planet.loadPlugin(autoscale({extraHeight: -120})); planet.loadPlugin(planetaryjs.plugins.earth({ topojson: { file: 'https://101.43.39.125/HexoFiles/js/planetaryjs/world-110m.json' }, oceans: { fill: '#001320' }, land: { fill: '#06304e' }, borders: { stroke: '#001320' } })); planet.loadPlugin(planetaryjs.plugins.pings()); planet.loadPlugin(planetaryjs.plugins.zoom({ scaleExtent: [50, 5000] })); planet.loadPlugin(planetaryjs.plugins.drag({ onDragStart: function() { this.plugins.autorotate.pause(); }, onDragEnd: function() { this.plugins.autorotate.resume(); } })); planet.loadPlugin(autorotate(5)); planet.projection.rotate([100, -10, 0]); planet.draw(canvas); // Plugin to resize the canvas to fill the window and to // automatically center the planet when the window size changes function autocenter(options) { options = options || {}; var needsCentering = false; var globe = null; var resize = function() { var width = window.outerWidth /2 + (options.extraWidth || 0); var height = window.outerHeight/2 + (options.extraHeight || 0); globe.canvas.width = width; globe.canvas.height = height; globe.projection.translate([width / 2, height / 2]); }; return function(planet) { globe = planet; planet.onInit(function() { needsCentering = true; d3.select(window).on('resize', function() { needsCentering = true; }); }); planet.onDraw(function() { if (needsCentering) { resize(); needsCentering = false; } }); }; }; // Plugin to automatically scale the planet's projection based // on the window size when the planet is initia
使用立即执行函数而不是直接暴露也做到来私有化private的意思,比如有5个函数,我只想暴露1个函数给别人,那么window.js1 = {你想暴露的1个函数},这样别人就只能访问你暴露的唯一函数,另外4个访问不了。
其实,效果的话,没有效果,比较枯燥,但是他的JS de 格式写的着实不错,继承,重写一一用到,接下来看代码:
seajs遵循CMD规范,requirejs遵循AMD规范。AMD规范是预加载,CMD规范是赖加载。 下文举例假设有文件 b.js, c.js如下 //b.js define(function(require, exports, module){ console.log('b is loaded') function run(){ console.log('b run'); } exports.run = run; }) //c.js define(fun
(function (js_body) { // 脱壳 && 解密 let js_arr = js_body.split("\n").pop().split(';'), fun_name = /var\s+(_0x[a-z0-9]+)=/.exec(js_arr[6])[1], reg_str = fun_name + '\\(' + "'([^']+)',\s*'([^']+)'" + '\\)', js_str = js_arr.slice
删除掉没用到的 __webpack_require__.d、__webpack_require__.r、 __webpack_require__.t、__webpack_require__.n 、__webpack_require__.o 、 __webpack_require__.p,剩下的代码如下:
JS加密,即JavaScript代码加密混淆,是指对js代码进行数据加密、逻辑混淆。 使js代码不能被分析、复制、盗用,以达到保护js代码、保护js产品、保护js知识产权的目的。
Web 页面中的 JS 与 iOS Native 如何交互?JS 和 iOS Native 就好比两块没有交集的大陆,如果想要使它们相互通信就必须要建立一座“桥梁”。
我们来说全局配置,我们知道导入require.js之后会设置data-main属性来执行入口文件,然后再入口文件中进行require的配置。
在JavaScript发展初期就是为了实现简单的页面交互逻辑,寥寥数语即可;如今CPU、浏览器性能得到了极大的提升,很多页面逻辑迁移到了客户端(表单验证等),随着web2.0时代的到来,Ajax技术得到广泛应用,jQuery等前端库层出不穷,前端代码日益膨胀,此时在JS方面就会考虑使用模块化规范去管理。 本文内容主要有理解模块化,为什么要模块化,模块化的优缺点以及模块化规范,并且介绍下开发中最流行的CommonJS, AMD, ES6、CMD规范。本文试图站在小白的角度,用通俗易懂的笔调介绍这些枯燥无味的概念,希望诸君阅读后,对模块化编程有个全新的认识和理解!
随着网站功能逐渐丰富,网页中的js也变得越来越复杂和臃肿,原有通过script标签来导入一个个的js文件这种方式已经不能满足现在互联网开发模式,我们需要团队协作、模块复用、单元测试等等一系列复杂的需求
ejs项目大名鼎鼎,应该就不需要介绍了,主要收获就是得知了实现一个模板引擎的流程,ejs是将模板作为字符串逐个解析,遇到正常的html代码,就放进一个数组中去,遇到js代码则进行过滤器、包含等的处理,最后数组join成一个可以成为Function构造函数第二个参数的字符串,构造成构造函数之后就是调用返回最终的html字符串。以下是阅读源码的笔记,因为源码中遗憾有很多说明,所以笔记很少。
上例子通过jquery方法将页面的背景颜色改成红色,所以必须先引入jQuery库,就把这个库当作参数传入。这样做除了保证模块的独立性,还使得模块之间的依赖关系变得明显。
为了方便资源管理和提升工作效率,常用的js和css文件的加载应该放在一个统一文件里面完成,也方便后续的资源维护。所以我用js写了以下方法,存放在“sourceController.js”文件内。 /** * Created by MingChen on 2016/11/3. */ function sourceController() { this.root = ""; this.callfunc = null; // 回调函数 this.css = []; thi
对于web项目来说,打交道的不仅仅有后台,前台页面也是少不了的,而前台的页面js也常常是我们后台程序员必须要使用的语言, 今天说下项目中的js的组织方式。
在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护。
将一个复杂的程序按照一定的规范,封装成几个块(文件),并进行组合在一起。 这些模块,最好都做到可复用性,比如可以在多个文件中使用处理时间的模块。
利用localStorage储存js文件,只有在第一次访问该页面的时候加载js文件,以后在访问的时候加载本地localStorage执行
React.js和Vue.js都是很好的框架。而且Next.js和Nuxt.js甚至将它们带入了一个新的高度,这有助于我们以更少的配置和更好的可维护性来创建应用程序。但是,如果你必须经常在框架之间切换,在深入探讨另一个框架之后,你可能会轻易忘记另一个框架中的语法。在本文中,我总结了这些框架的基本语法和方案,然后并排列出。我希望这可以帮助我们尽快掌握语法,不过限于篇幅,这篇文章只比较React.js和Vue.js,下一篇再谈Next.js个Nuxt.js。
随着JS越来越庞大,已经不仅仅是以前复制粘贴做特效的时代了,JS越来越偏向于业务逻辑与应用。恰逢Node的流行,JS在web开发中占有越来越重要的地位。由于JS代码庞大,文件数目多,传统的使用<script src=""></script>会带来很多性能的问题,因此requirejs可以为我们提供两种解决思路: 1 模块化组织JS 2 异步加载JS文件 有了这两种解决办法,能有效的帮助我们解决前端代码库的组织难题。 本文下面就模拟一个小例子,由于并没有应用实践,因此命名很戳,还
区别:一:js的数据类型和java类似。只不过js中的数据类型number将java中的int,double,float整合了。 二:js中可以不用声明变量类型。变量不声明数据类型的话,那么他的类型取决于当前的值是什么数据类型。举例:
项目中一直用的都是webpack,前一段需要开发几个类库供其他平台使用,本来打算继续用webpack的,但感觉webpack用来开发js库,不仅繁琐而且打包后的文件体积也比较大。正好之前看vue源码,知道vue也是通过rollup打包的。这次又是开发类库的,于是就快速上手了rollup。
随着前端复杂度的不断提升,诞生出很多打包工具,比如最先的grunt,gulp。到后来的webpack和Parcel。但是目前很多脚手架工具,比如vue-cli已经帮我们集成了一些构建工具的使用。有的时候我们可能并不知道其内部的实现原理。其实了解这些工具的工作方式可以帮助我们更好理解和使用这些工具,也方便我们在项目开发中应用。
第三方的js文件,自己写的js文件,js越来越多了怎么办? 提出问题: 1、js文件太多了,每个页面都写<script src="...">太麻烦。 2、如果路径变化了,或者js名称变化了怎么办?每个页面都改一遍吗? 3、如何约束js文件的加载顺序?a.js定义了一个函数,b.js要调用,但是b.js先加载了,a.js还没加载完成,造成函数未定义,无法调用。 4、js文件的合并。开发阶段,js会分成多个文件,这样便于开发。但是成熟了之后会合并成一个文件。这样引用方式就会变化,原先引用一堆js,现在只需要引用
下面是一个使用 react 的业务的代码依赖,但是实际上业务代码中并没有对依赖图中标识的模块,也就是说构建工具将不需要的代码打包到了最终的代码当中。显然,这是很不合理的。
继续打开 github 看一下最初的版本的 babel 是怎么实现的,了解它的基本原理。
无论你开发使用的是 CommonJS 规范还是 ES6 模块规范,打包后的文件都统一使用 webpack 自定义的模块规范来管理、加载模块。本文将从一个简单的示例开始,来讲解 webpack 模块加载原理。
js本身的问题: 不具有模块化的语法规则,在语言层面没有命名空间。 JavaScript 编程过程中很多时候,我们都在修改变量,在一个复杂的项目开发过程中,如何管理函数和变量作用域,显得尤为重要。
我们知道最常见的模块化方案有CommonJS、AMD、CMD、ES6,AMD规范一般用于浏览器,异步的,因为模块加载是异步的,js解释是同步的,所以有时候导致依赖还没加载完毕,同步的代码运行结束;CommonJS规范一般用于服务端,同步的,因为在服务器端所有文件都存储在本地的硬盘上,传输速率快而且稳定。
作者:海因斯坦,原文链接:https://juejin.im/post/6893809205183479822
简介 在最开始学习前端的时候只需要一个js文件就能玩转一个小的练手应用,但是随着自己不断的学习,ajax、jQuery等广泛应用,使得我们的代码量变得巨大,代码变得格外的混乱。现在迫切的需要我们将大段的代码分离开来。 前端最开始并没有像java中package概念以及import那样的引包工具。JavaScript源生代码是在ES6的时候才正式的引入import这个API,来调用其他文件。在这之前也同样出现了很多社区来实现模块化开发。 ---- 发展历程 注意下面会讲历史上面出现的一些类库,有一些现在已经没
TypeScript 模块 TypeScript 模块的设计理念是可以更换的组织代码。
是的,在webpack v4中,不再需要配置UglifyjsWebpackPlugin。(详情请见:文档) 取而代之的是,更加方便的配置方法。
我这里以Java实现的,单表查询就不贴具体代码了,这里只展示具体返回的json格式数据和入参数据
上面我们已经讲过了两节课了,感兴趣的伙伴,可以看看上面两节课的内容,大神勿扰,欢迎评论,给我提出更好的建议,谢谢。
消除游戏-消消乐 一个基于HTML,Javascript的消除游戏。使用了createjs框架。 ---- -> view online demo ---- screenshot: Example 1: 📷 Example “hint()”: 📷 Example [col&row]: { col:20, //set 20 columns row:16, //set 16 rows } 📷 usage: <canv02
高阶函数就是那种输入参数里面有一个或者多个函数,输出也是函数的函数,这个在js里面主要是利用闭包实现的,最简单的就是经常看到的在一个函数内部输出另一个函数,比如
为了研究与学习某些测试框架的工作原理,同时也为了完成培训中实现一个简单的测试框架的原因,我对should.js的代码进行了学习与分析,现在与大家来进行交流下。
在nodejs,exports 是 module.exports的引用,初始化时,它们都指向同一个{}对象。
以北京市为例,级别编码变为1,北京市的区域编码作为查询条件的父级编码,依次类推即可
大家知不知道每次用js逆向时,发现那些长长的js代码,那可不是人写的。那到底是怎么来的,前端的人应该都知道用框架生成的,没错就是webpack
本来想一气呵成,把加载的过程都写了,但是卡着呢,所以只好在分成两份了。 1、页面里使用<script>来加载 boot.js 。 2、然后在boot.js里面动态加载 bootLoad.js。以时间作为标识 var dateVer = date.getYear() + '_' + date.getMonth() + '_' + date.getDate() + '_' + date.getHours(); 这样可以保证一小时内肯定会被更新。同时也避免了每次都去更新。 3、boot.js里面根
最近新项目需要根据参数切换js的版本,就需要动态加载js,动态加载js涉及到异步加载与同步加载的问题,所以就封装了一下下面两个方法,以供使用。
领取专属 10元无门槛券
手把手带您无忧上云