草庐IT

function-prototypes

全部标签

Javascript 原型(prototype)和访问类的问题

Family=function(name){this._Name=name;}Family.prototype={getName:function(){returnthis._Name;},People:function(num){this._Number=num;}}Family.People.prototype={clearNumber:function(){this._Number=0;}}People是一个嵌套类。它的父类是Family。我得到的错误是Family.People未定义。有人可以更正上面的代码吗? 最佳答案 工

javascript - 中级 JavaScript : assign a function with its parameter to a variable and execute later

我有一个JavaScript函数:functionalertMe($a){alert($a);}我可以这样执行:alertMe("Hello");我想做的是将带有"Hello"参数的alertMe("Hello")赋给一个变量$func,然后稍后可以通过执行$func();之类的操作来执行此操作。 最佳答案 我想添加评论作为答案代码//definethefunctionfunctionalertMe(a){//returnthewrappedfunctionreturnfunction(){alert(a);}}//declaret

javascript - 使用 (function() { … }).call(this) 包装文件与使用简单 () 进行调用

这个问题在这里已经有了答案:Reasonbehindthisselfinvokinganonymousfunctionvariant(5个答案)关闭8年前。backbone.js源代码使用这样的函数包装器:(function(){...}).call(this);见http://backbonejs.org/docs/backbone.html#section-185.更常见的是,我看到使用以下内容:(function(){...})();这两者的行为何时不同?我的印象是它们是等价的,但我认为鉴于Backbone使用.call(this)而不是较短的替代方案,所以一定存在差异。

javascript - app.configure(function){} typeerror undefined is not a function

我正在使用socket.io和angularjs创建一个聊天应用程序,当我使用cmd运行app.js文件时,我收到一条错误消息“app.configure(function){}typeerrorundefinedisnotafunction”可能是什么问题?我的代码是这样的:varhttp=require('http');varexpress=require('express'),routes=require('./routes'),socket=require('./routes/socket.js');app=module.exports.app=express();varser

javascript - 类型错误 : task is not a function in async js parrallel

我正在尝试使用以下代码上传图像并更新数据库集合中图像的url。Controller.prototype.handle=function(req,res,next){varid=req.params.id,controller=req.params.controller,optionalController;optionalController=_.clone(controller);//handleoptionalcontrollerif(controller==='newboat'){controller='boat';}elseif(controller==='newcrew'){

javascript - Angular CLI - 如何在整个应用程序中共享原型(prototype)函数

我需要在字符串类上有一些全局原型(prototype)函数。例如。string.prototype.trimWhiteSpaces=function(){returnthis.replace(/+/g,'');}我正在使用AngularCLI,我希望我的Angular4应用程序中的所有字符串都可以访问此函数。我已将代码片段添加到名为prototypes.js的文件中,并在.angular-cli.json中加载了该文件"scripts":["assets/js/prototypes.js","../node_modules/jquery/dist/jquery.min.js","../

javascript - Object.keys(anObject) 是否返回一个对象的原型(prototype)?

这个问题在这里已经有了答案:Whydoesjavascript's"in"operatorreturntruewhentestingif0existsinanarraythatdoesn'tcontain0?(6个答案)关闭4年前。我正在阅读EloquentJavaScript'sMapsection我无法理解它的最后一段:Ifyoudohaveaplainobjectthatyouneedtotreatasamapforsomereason,itisusefultoknowthatObject.keysreturnsonlyanobject’sownkeys,notthoseinth

javascript - 来自 prototype.js 第 3877 行的 "undefined handler"

一个非常小众的问题:我有时(30%的时间)在prototype.js库(来自google的版本1.6.0.2:http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js)的第3877行收到“未定义的处理程序”javascript错误。现在在这个页面上我有一个谷歌地图,我使用原型(prototype)窗口库。问题出现在IE7和FF3中。这是FireBug提供的信息:handlerisundefined?inprototype.js@3871()prototype.js(line3877)handler.call(

javascript - JavaScript 中的原型(prototype)继承约定

我看到很多这样的代码:functionBase(){}functionSub(){}Sub.prototype=newBase();但是,如果您这样做:s=newSub();print(s.constructor==Sub);这是错误的。这让我感到困惑,因为s的构造函数确实是Sub。这样做是传统的/更好的吗?functionBase(){}functionSub(){}Sub.prototype=newBase();Sub.prototype.constructor=Sub;还是真的不重要? 最佳答案 'constructor'并不

javascript - IE7 中的 Element.prototype?

我正在尝试扩展所有dom元素,以便我可以获取和删除它们的子元素。该功能如下(适用于FF和Chrome)。IE7中是否有等效项来扩展基本dom对象?if(!Element.get){Element.prototype.get=function(id){for(vari=0;i谢谢! 最佳答案 这是一个简单的解决方法,在99%的情况下都足够了。它也可以按照您的脚本的要求完成:if(!window.Element){Element=function(){};var__createElement=document.createElement