草庐IT

private-functions

全部标签

javascript - Angular Testing : Spy a function that was executed on the initialize of a controller

我一直在尝试监视在Controller初始化时执行的函数,但测试总是失败。我一直在尝试执行$scope.$digest()但它不起作用,但是在控制台中,我看到该函数已被调用。我想不通,有人可以向我解释为什么它不起作用吗?代码笔示例:http://codepen.io/gpincheiraa/pen/KzZNbyControllerfunctionController($stateParams,$scope){$scope.requestAuthorization=requestAuthorization;if($stateParams.requestAuthorization===tr

javascript - .then(functionReference) 和 .then(function(value){return functionReference(value)}) 之间有区别吗?

给定一个用于处理Promise值的命名函数functionhandlePromise(data){//dostuffwith`data`returndata}a)将命名函数handlePromise作为对.then()的引用传递promise.then(handlePromise)b)使用匿名函数或命名函数作为.then()的参数,并以Promise值作为参数返回命名函数handlePromise在传递给.then()的匿名或命名函数的主体内promise.then(function/*[functionName]*/(data){returnhandlePromise(data)})

javascript - JS 继承 : calling the parent's function from within the child's function

JS对象模型肯定有不明白的地方。来自这些资源:PrototypesBasicOOPinJS-InheritanceObject.create()我收集了我认为或认为是对象模型的准确心理表征。在这里:所有对象都有一个属性,文档将其称为[[Prototype]]。[[Prototype]]可以被认为是对对象父对象的引用。更准确地说:Thereferencetothe[parent's]prototypeobjectiscopiedtotheinternal[[Prototype]]propertyofthenewinstance.(source1)您可以使用Object.getProtot

javascript - 类型错误 : is not a function typescript class

我在typescript类中遇到以下错误,无法理解原因。我所做的只是尝试调用传递token的辅助函数。错误:posterror:TypeError:this.storeTokenisnotafunction(…)类:/***AuthenticationService:**Containsthehttprequestlogictoauthenticatethe*user.*/import{Injectable}from'@angular/core';import{Http,Response,Headers,RequestOptions}from'@angular/http';import

原型(prototype)上的 Javascript 私有(private)成员

好吧,我试图弄清楚这是否可能。这是代码:a=function(text){varb=text;if(!arguments.callee.prototype.get)arguments.callee.prototype.get=function(){returnb;}elsealert('alreadycreated!');}varc=newa("test");//createsprototypeinstanceofgettervard=newa("ojoj");//alertsalreadycreatedalert(c.get())//alertstestalert(d.get())/

javascript - 如何在 Javascript 中实现 "function timeout"- 而不仅仅是 'setTimeout'

如何实现timeout在Javascript中,不是window.timeout而是类似sessiontimeout或sockettimeout-基本上-“functiontimeout"Aspecifiedperiodoftimethatwillbeallowedtoelapseinasystembeforeaspecifiedeventistotakeplace,unlessanotherspecifiedeventoccursfirst;ineithercase,theperiodisterminatedwheneithereventtakesplace.具体来说,我想要一个ja

javascript - 禁用 "use the function form of use strict"但保留 "Missing ' 使用严格声明“警告

我正在使用jslint来验证我的代码。我的所有页面上都有“严格使用”。如何禁用消息“使用'usestrict'的函数形式”但保留“缺少'usestrict'语句”警告,这样我就不会忘记将它放在新文件上?谢谢 最佳答案 根据Crockford'spost,您需要将所有内容包装在一个函数中...(function(){"usestrict";//therestofyourfilegoeshere...}());你也可以使用jshint相反,它有一个“globalstrict”选项,可以完全按照您的要求进行操作,而无需将所有内容都包装在一

javascript - 在 Javascript 中强制执行私有(private)方法是个好主意吗?

我正在与一位开发人员讨论侵入javascript私有(private)函数是否有意义。备选方案是:一个构造函数和一个包含所有函数的原型(prototype),非API方法(私有(private))将仅使用下划线_function_name命名,以便开发人员知道他们可以调用什么,不能调用什么。API函数的构造函数和原型(prototype),以及在私有(private)命名空间内作为私有(private)函数的自由函数,除了这个命名空间之外,其他命名空间都隐藏了它们。我们不考虑其他方法,例如在varprivate_var=function(){}形式的构造函数中创建私有(private)

javascript - 是否可以动态访问模块模式中的私有(private)变量?

有没有办法让模块模式中的公共(public)函数动态访问私有(private)变量?test1显示了我所说的“动态访问”但使用公共(public)变量的意思varx=(function(){varx=0,y=2,z=5;return{toast:123,test1:function(arg){returnthis[arg];},test2:function(){//??}};}());console.log(x.test1("toast"));//123console.log(x.test2("y"));//shouldreturn2我最终创建了一个私有(private)变量(一个对象

javascript - $(document).ready(function()?

这个问题在这里已经有了答案:document.readyinsidebodytag(2个答案)关闭9年前。我们经常在这里和那里读到,我们必须将我们的js代码放在页面头部或之前(抱歉)结束主体标记。关于这个的讨论放在一边,我只是想知道浏览器对这些东西的阅读顺序是什么(假设他们在这里表现得是平等的):我们可以放置:$(document).ready(function(){无论在页面结构的哪个位置,因为我们正在使用$(document).ready还是应该将它放在head部分?谁能澄清一下。如果我的问题不清楚,我可以重新措辞。