下面是个require.js,我们项目(一个ionic项目)里用到的,google得到的信息也不多。
上网查了一下,得知有什么nodejs按照CommonJS实现的requirejs,还有AMD规范的requirejs,但是我们项目里用的是下面的这个require.js,用法和AMD的写法不一样,和nodejs的比较像,而且用gulp也能对这个进行打包,我想问问这到的是个什么东西,还有它说是Smoothie的一部分,不知道这个Smoothie是个什么项目。兼容性貌似也不是很好,Android5.0以下是不支持这玩意的,如果我想兼容个IE8(或者放宽到IE9也行)什么的,在浏览器的环境下有什么requireJS能够供我选择呢?
//
// This file is part of Smoothie.
//
// Copyright (C) 2013-2015 Flowy Apps GmbH
//
// Smoothie is free software: you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option) any
// later version.
//
// Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
// A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.You should have received a copy of the GNU Lesser General Public
// License along with Smoothie. If not, see .
//
////////////////////////////////////////////////////////////////////////////////
// INFO Standalone require()
// This is a stripped down standalone version of Smoothie's require
// function. If you also like to have a 'bootloader', which gives you some
// nice hooks to execute code on different loading states of the document
// and keeps your JavaScript completely separate from your HTML, we
// recommend to load smoothie.js from the library's root directory.
// NOTE The load parameter points to the function, which prepares the
// environment for each module and runs its code. Scroll down to the end of
// the file to see the function definition.
(function(load) { 'use strict';
var SmoothieError = function(message, fileName, lineNumber) {
this.name = "SmoothieError";
this.message = message;
}
SmoothieError.prototype = Object.create(Error.prototype);
// NOTE Mozilla still sets the wrong fileName porperty for errors that occur
// inside an eval call (even with sourceURL). However, the stack
// contains the correct source, so it can be used to re-threw the error
// with the correct fileName property.
// NOTE Re-threwing a new error object will mess up the stack trace and the
// column number.
if (typeof (new Error()).fileName == "string") {
self.addEventListener("error", function(evt) {
if (evt.error instanceof Error) {
if (pwd[0]) {
evt.preventDefault();
throw new evt.error.constructor(evt.error.message, pwd[0].uri, evt.error.lineNumber);
}
else {
var m = evt.error.stack.match(/^[^\n@]*@([^\n]+):\d+:\d+/);
if (m === null) {
console.warn("Smoothie: unable to read file name from stack");
}
else if (evt.error.fileName != m[1]) {
evt.preventDefault();
throw new evt.error.constructor(evt.error.message, m[1], evt.error.lineNumber);
}
}
}
}, false);
}
// INFO Current module descriptors
// pwd[0] contains the descriptor of the currently loaded module,
// pwd[1] contains the descriptor its parent module and so on.
var pwd = Array();
// INFO Path parser
// NOTE Older browsers don't support the URL interface, therefore we use an
// anchor element as parser in that case. Thes breaks web worker support,
// but we don't care since these browser also don't support web workers.
var parser = URL ? new URL(location.href) : document.createElement('A');
// INFO Module cache
// NOTE Contains getter functions for the exports objects of all the loaded
// modules. The getter for the module 'mymod' is name '$name' to prevent
// collisions with predefined object properties (see note below).
// As long as a module has not been loaded the getter is either undefined
// or contains the module code as a function (in case the module has been
// pre-loaded in a bundle).
// NOTE IE8 supports defineProperty only for DOM objects, therfore we use a
// HTMLpElement as cache in that case. This breaks web worker support,
// but we don't care since IE8 has no web workers at all.
try {
var cache = new Object();
Object.defineProperty(cache, "foo", {'value':"bar",'configurable':true});
delete cache.foo;
}
catch (e) {
console.warn("Falling back to DOM workaround for defineProperty: "+e);
cache = document.createElement('p');
}
// INFO Send lock
// NOTE Sending the request causes the event loop to continue. Therefore
// pending AJAX load events for the same url might be executed before
// the synchronous onLoad is called. This should be no problem, but in
// Chrome the responseText of the sneaked in load events will be empty.
// Therefore we have to lock the loading while executing send().
var lock = new Object();
// INFO Smoothie options
// The values can be set by defining a object called Smoothie. The
// Smoothe object has to be defined before this script here is loaded
// and changing the values in the Smoothie object will have no effect
// afterwards!
var requirePath = self.Smoothie&&self.Smoothie.requirePath!==undefined ? self.Smoothie.requirePath.slice(0) : ['./'];
var requireCompiler = self.Smoothie&&self.Smoothie.requireCompiler!==undefined ? self.Smoothie.requireCompiler : null;
// NOTE Parse module root paths
var base = [location.origin, location.href.substr(0, location.href.lastIndexOf("/")+1)];
for (var i=0; i
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
小伙看你根骨奇佳,潜力无限,来学PHP伐。