草庐IT

private_method

全部标签

javascript - 在对显示模块进行单元测试时如何 stub 私有(private)函数

我一直在构建一个Node模块,它包装了对GitHubAPI的大量调用,并且以我无限的智慧使用揭示模块模式构建了这个模块,使我的包装函数保持私有(private)并且只公开简单的方法。请参见下面的示例:github.shortcuts=(function(){varappPath;varcreateRepo=function(name){vardeferred=Q.defer();github.repos.create({name:name,auto_init:true},function(error,result){if(error){deferred.reject(newError(

私有(private)属性的 Javascript 动态 getter/setter

我想动态地创建getter/setter方法来检索私有(private)属性。这是我做的。首先,我制作了这个类:functionwinClass(posX,posY,w,h){varx=posX||0;vary=posY||0;varwidth=w||0;varheight=h||0;}然后我用getter/setter方法扩展了winClass,如下:winClass.prototype.getX=function(){returnx;}winClass.prototype.setX=function(val){x=val;}然后我测试了:varwin1=newwinClass(10

javascript - Mootools 类中的私有(private)方法

我对在Javascript中使用oop比较陌生,我想知道私有(private)方法的最佳实践是什么。现在,我正在使用mootools创建我的类,并通过在私有(private)方法前加上下划线并强制自己不要在类外部调用该方法来模拟私有(private)方法。所以我的课看起来像:varNotifier=newClass({...showMessage:function(message){//publicmethod...},_setElementClass:function(class){//privatemethod...}});这是在JS中处理私有(private)方法的良好/标准方式

javascript - 未捕获的类型错误 : Cannot call method 'replace' of null

如果我在ChromeJS控制台上输入“_.template($('#pranks-list').html())”,它也能正常工作>>_.template($('#pranks-list').html())function(a){returne.call(this,a,b)}应用程序.js//Viewwindow.PranksListView=Backbone.View.extend({template:_.template($('#pranks-list').html())});索引.html'>为什么我会在这一行出现这个错误??template:_.template($('#pran

Javascript 模块模式 : How to inject/create/extend methods/plugin to our own library?

我是javascript的新手。对不起,如果我的问题有任何问题。如何将方法或插件注入(inject)/创建/扩展到我们自己的库中?这是“yourlib.js”varYourlib=(function(){//privt.varvarselectedEl={}//someprivt.functfunctionsomething(){}return{getById:function(){},setColor:function(){}}}());下面是你的“plugin.js”/*Howtocreatethepluginpattern?Example:Iwanttocreate/inject

javascript - 为什么IE会报错: Object doesn't support property or method isNaN

我在IE11中遇到这个错误:Objectdoesn'tsupportpropertyormethodisNaNJavaScriptjQuery(document).ready(function($){var$total=$('#total'),$value=$('.value');$firstName=$('#firstname');$lastName=$('#lastname');$tour=$('#tour');$pledge=$('#pledge');$currency=$('#currency');$distance=$('#distance');$riders=$('#rid

javascript - 如何创建公共(public)和私有(private)成员?

我有点困惑,如何创建公共(public)和私有(private)成员。到目前为止我的代码模板是这样的:(function()){var_blah=1;someFunction=function(){alert(_blah);};someOtherFunction=function(){someFunction();}}(); 最佳答案 您可能想要使用YahooModulePattern:myModule=function(){//"private"variables:varmyPrivateVar="Icanbeaccessedon

javascript - UnderscoreJS 未捕获类型错误 : Cannot call method 'replace' of undefined

在我的BackboneView中我有:noteTemplate:_.template($('#note-template').html()),这是抛出这个错误。模板是:Created3daysagoIn3hours我很困惑,因为这在我的控制台中有效:>>_.template($('#note-template').html());函数(n){returne.call(this,n,w)}完整代码如下:App.Views.Index=Backbone.View.extend({el:$("div.reminders"),todays:$("span.today"),tomorrows:$

javascript - 未捕获的类型错误 : Cannot call method 'request' of undefined

在我的javascript代码中,我不断收到以下错误:未捕获的类型错误:无法调用未定义的方法“请求”我的Javascript在下面。如有任何帮助,我们将不胜感激!myJsonStore={store1:newExt.data.JsonStore({root:'rootstore1',fields:['UserID','UserName']})};//------Mypanel------items:[{xtype:'combo',id:'UName',fieldLabel:'User',emptyText:'All',store:myJsonStore.store1,displayFi

Javascript 表单提交 : Object doesn't support this property or method (IE7)

我正在尝试使用javascript提交表单。Firefox工作正常,但IE在此函数的提交行上提示“对象不支持此属性或方法”:functionsubmitPGV(formName,action){vargvString="";pgVisibilities.each(function(pair){gvString+=pair.key+":"+pair.value+",";});$('pgv_input').value=gvString;varform=$(formName);form.action=action;form.submit();}在这里调用:这是表格:有什么想法吗?