草庐IT

return-type-requirement

全部标签

javascript - require.js 文本插件将 ".js"添加到文件名

我正在尝试使用requirejs和文本插件,但我遇到了奇怪的问题。我有两个网络服务器:localhost:3000-充当CDN并拥有所有静态文件:js、图像、css和模板localhost:3001-服务器-作为REST服务器,只提供一个文件,即main.html文件main.html文件使用以下行从第二个服务器加载所有js文件:由于某些原因,在使用requirejs文本插件时,他在导航到localhost:3001时向模板添加".js"后缀>我正在使用以下语法:define['jquery','backbone','underscore','models/model','text!t

JavaScript 模块模式 - 使用 "return this"怎么样?

在阅读了一些有关模块模式的内容后,我看到了几种返回您想要公开的属性的方法。除了私有(private)属性和方法之外,最常见的方法之一是在“return”语句中声明您的公共(public)属性和方法。一种类似的方式(“揭示”模式)是提供对您希望公开的属性和方法的简单引用。最后,我看到的第三种技术是在模块函数内创建一个新对象,在返回所述对象之前将新属性分配给该对象。这是一个有趣的想法,但需要创建一个新对象。所以我在想,为什么不直接使用this.propertyName来分配你的公共(public)属性和方法,最后使用returnthis呢?这种方式对我来说似乎更简单,因为您可以使用通常的v

javascript - http ://required Cross Origin Resource Sharing (CORS) and preflight only happen in IE 的 XMLHttpRequest

我是一名前端开发人员。我只在客户端编码,所以我不确定是否存在错误。我一直在搜索CORS,但仍然不知道我的问题是什么。我正在尝试将数据发布到REST。$.ajax({url:urlPost,type:"POST",data:JSON.stringify(obj),dataType:"json",contentType:"application/json",success:function(res){console.log(JSON.stringify(res));},error:function(res){console.log("Badthinghappend!"+res.status

javascript - react /归约形式 : how to return promise from onSubmit?

我正在努力思考redux,react-redux和redux-form.我已经设置了一个商店并从redux-form添加了reducer。我的表单组件如下所示:登录表单importReact,{Component,PropTypes}from'react'import{reduxForm}from'redux-form'import{login}from'../../actions/authActions'constfields=['username','password'];classLoginFormextendsComponent{onSubmit(formData,dispat

javascript - typescript TS7015 : Element implicitly has an 'any' type because index expression is not of type 'number'

我在Angular2应用程序中遇到此编译错误:TS7015:Elementimplicitlyhasan'any'typebecauseindexexpressionisnotoftype'number'.导致它的代码是:getApplicationCount(state:string){returnthis.applicationsByState[state]?this.applicationsByState[state].length:0;}但这不会导致此错误:getApplicationCount(state:string){returnthis.applicationsBySt

javascript - Require JS 忽略了我的配置

我的脚本目录结构非常简单:/js/由于站点引擎使用干净的URL,我在中使用绝对路径:RequireJS配置:requirejs.config({baseUrl:"/js/libs",paths:{"jquery":"jquery-1.10.1.min","knockout":"knockout-2.2.1","komapping":"knockout.mapping"}});HTML中的某处:require(["jquery","knockout","komapping"],function($,ko,mapping){//...});所以问题是RequireJS完全忽略了baseUr

javascript - ES6 中是否有针对 ES5 `module.exports = require(' ./inner.js')` 的任何一行类比?

//beforemodule.exports=require('./inner.js');//nowadaysexportdefaultfrom'./inner.js';我正在尝试这样做,但babel只允许在es7阶段1中使用proposalfornow.所以现在,我坚持这两行:importstickerfrom'./box-sticker.jsx';exportdefaultsticker;我可以将它们缩短为一个吗? 最佳答案 你应该可以做到export{defaultasdefault}from'./inner.js';//or

javascript - 何时使用 return,返回的数据会怎样?

有什么区别:functionbla1(x){console.log(x)}和functionbla(x){returnconsole.log(x)}在什么情况下我应该使用return?另外,当函数返回一个值时,它会发生什么?它存储在某个地方吗? 最佳答案 Whatisthedifference第一个函数返回undefined(因为它没有明确地返回任何东西),第二个函数返回console.log返回的任何内容。InwhichcasesshouldIusereturn?当函数正在生成一些值并且您想将其传递回调用者时。以Math.pow为

javascript - 尝试使用 gh-pages 部署我的 React 应用程序但收到此错误消息 : The "file" argument must be of type string. Received type undefined

我试图用gh-pages部署我的React应用程序,但我遇到了这个错误:"file"参数必须是字符串类型。接收类型未定义。起初,我以为这是我的代码,所以我制作了另一个没有修改的create-react-app,尝试使用npmrundeploy命令进行部署,但再次收到此错误消息。我的package.json(我添加了我的homepage链接、predeploy和deploy脚本,以及gh-页面依赖):"name":"test-deploy","version":"0.1.0","private":true,"homepage":"https://vnsteven.github.io/te

javascript - 错误 TS7017 : Index signature of object type implicitly has an 'any' type in form validation angular 2

我在给出的Angular2中进行响应式(Reactive)验证时遇到编译错误errorTS7017:Indexsignatureofobjecttypeimplicitlyhasan'any'type为了this.comErrors[field]='';constmessages=this.validationMessages[field];this.comErrors[field]+=messages[key]+'';它正在按应有的方式运行,但是当我尝试运行npmrunbuild.prod时,出现错误并且无法构建我的项目这是我的代码:onValueChanged(data?:any)