进一步了解Javascript和OO编程,但我不明白这个行为的原因我的ojbect(myUser无法访问属性this.first_name作为'jon'而是未定义(在底部的屏幕截图中以红色亮起)这是有问题的代码片段:
function User(first_name, last_name){
this.first_name=first_name;
this.last_name=last_name;
}
// left in for completeness
User.prototype = {
constructor: User,
sayName: function(){
console.log("My Name: " + this.first_name + " and " + this.last_name);
}
}
User.prototype.whoWhat = function(){
console.log(this.first_name + " I want to tell you now " + Math.random());
}
var myUser=new User('jon', 'johnson');
myUser.sayName();
myUser.whoWhat();
setInterval(myUser.whoWhat, 3000);
Run Code Online (Sandbox Code Playgroud)
这是控制台输出:

我不是一个全职的JS开发人员,虽然我觉得我已经永远使用它了.大多数闭包的讨论都是有道理的.我很好奇全局window对象是否只是全局关闭?我已经阅读了http://lostechies.com/derickbailey/2011/11/30/is-javascripts-global-scope-really-just-a-closure/,但它似乎没有回答是的问题 - 或者-没门.
我开始收到此错误,并想要一种方法来解决它:
You have already activated rake 10.1.1, but your Gemfile requires rake 10.1.0. Using bundle exec may solve this.
Run Code Online (Sandbox Code Playgroud)
我在RubyMine中运行它.我可以在我的Gemfile.lock中看到它指定10.1.0.我可以手动将我的Gemfile.lock更新到10.1.1吗?
如果我做:
$gem list
....
rake (10.1.1, 10.1.0, 10.0.4, 0.9.2.2)
Run Code Online (Sandbox Code Playgroud)
所以我不确定为什么它不仅仅适用于10.1.0?
这是RubyMine的完整输出:
/Users/jt/.rvm/rubies/ruby-1.9.3-p448/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/jt/.rvm/gems/ruby-1.9.3-p448/bin/rake spec
Testing started at 3:15 PM ...
rake aborted!
You have already activated rake 10.1.1, but your Gemfile requires rake 10.1.0. Using bundle exec may solve this.
/Users/jt/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:33:in `block in setup'
/Users/jt/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:19:in `setup'
/Users/jt/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler.rb:120:in `setup'
/Users/jt/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/setup.rb:17:in `<top (required)>'
/Users/jt/repos/app/config/boot.rb:6:in `<top (required)>'
/Users/jt/repos/app/config/application.rb:1:in `<top (required)>'
/Users/jt/repos/app/Rakefile:5:in …Run Code Online (Sandbox Code Playgroud) 我有一些像这样回来的JSON:
"items":[
{
"has_instore_image": false
}
]
Run Code Online (Sandbox Code Playgroud)
如果我输出这样的值:
NSLog(@"has_instore_image val: %@", [item objectForKey:@"has_instore_image"]);
Run Code Online (Sandbox Code Playgroud)
我明白了
has_instore_image val: 0
Run Code Online (Sandbox Code Playgroud)
但如果我这样测试:
if([item objectForKey:@"has_instore_image"]==0){
NSLog(@"no, there is not an instore image");
}else{
...
Run Code Online (Sandbox Code Playgroud)
它总是转到else语句......嗯......你怎么建议我得到BOOL值并测试?我在这里阅读了BOOL的问题,我只是感到困惑,因为我没想到这个问题.
谢谢
我有以下模型(这里是一个jsbin:http://jsbin.com/vadutezaci/1/edit?html,css,output ):
<div class='jt-header'>a header 1</div>
<div class='jt-detail'>a detail 1
<div class='jt-item-price'>12.34</div>
</div>
<div class='jt-header'>another header 2<div class='jt-item-price'>34.45</div></div>
<div class='jt-detail'>another detail 2
</div>
Run Code Online (Sandbox Code Playgroud)
基本上,如果jt-item-price在jt-detail内,我想附加到前面的jt-header; 这是上面的第一个对联.如果它已经在jt-header内,请保持原样(第二个对联),以便上述内容变为:
<div class='jt-header'>a header <div class='jt-item-price'>12.34</div>
</div>
<div class='jt-detail'>a detail
</div>
<div class='jt-header'>another header<div class='jt-item-price'>34.45</div></div>
<div class='jt-detail'>another detail
</div>
Run Code Online (Sandbox Code Playgroud)
我该怎么做?我会认为detach().appendTo()但我如何检测到jt-item-price在一个细节内?我如何将它告诉前面的jt-header(可能有介入的非jt-header元素) ?
谢谢
一个更现实的例子似乎打破了使用next():
<div class='jt-row'>
<div class='jt-header'>a header 1</div>
</div>
<div class='jt-row'>
<div class='jt-detail'>a detail 1
<div class='jt-item-price'>12.34</div>
</div>
</div>
<div class='jt-row'>
<div class='jt-header'>another header 2<div class='jt-item-price'>34.45</div></div>
</div>
<div class='jt-row'>
<div class='jt-detail'>another detail …Run Code Online (Sandbox Code Playgroud) 我们正在考虑将应用程序从obj-c迁移到Swift.一个问题是我们的obj-c代码中有一个UITableView,它具有类型Header或类型的对象Item.基本上,它解析了它在cellForRowAtIndexPath中的类型.Swift Arrays(据我所知)只能处理一种类型.鉴于此,我们如何处理UITableView中使用的两种不同类型?像DataObj这样的包装器对象我们每个工作都有可用的实例吗?
我刚刚开始使用Vuex,但是遇到了问题(这可能是我的一些无知的语法错误)。我有一个具有Liked_items的用户,并且有一个与项目不同的网络呼叫。
mutations: {
SET_TOGGLE_LIKED: (state, { global_id }) => {
alert('here is global_id: ' + global_id)
state.user.liked_items.find((obj,i) => {
if(obj.global_id === global_id){ // no global_id
console.log('that exists at i: ' + i + ' with length: ' + state.user.liked_items.length)
state.user.liked_items.splice(i, 1)
console.log('that exists at i: ' + state.user.liked_items.length)
}else{
console.log('that doesnot exist!')
}
})
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,从“ likely_items”列表中删除了一个项目之后,该事件似乎被召回,并且我收到一个错误消息,即undefined上不存在global_id。
我可以通过以下方式修复:
state.user.liked_items.find((obj,i) => {
if(obj){
if(obj.global_id === global_id){
Run Code Online (Sandbox Code Playgroud)
但是为什么我需要检查obj这里是否存在?
这是一个不太可能的事情,但我有一个包含以下内容的文件:
文档结构:/some/path/start.php
<?php
require_once '../../another/path/test.php';
?>
Run Code Online (Sandbox Code Playgroud)
和
/另一个/路径/test.php /另一个/路径/图像/
<?php
test.php
hello<img src='images/1.jpg'>
?>
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种方法来使所需文件(test.php)正确加载图像(本质上是重置它认为是当前目录的内容)。我不想强迫人们使用绝对路径,也不想在其中添加一些变量。有没有 php 结构来处理这个问题?我正在使用 Zend_Framework。也许相反,一个具有多个 index.php 文件的构造,这些文件通过绝对路径映射到我的 Zend Framework 启动脚本。
任何想法,将不胜感激?我有以下一个优雅的解决方案 - 我只是没有看到它。
乳清的评价是真的吗?
<?php
$val2=0;
//outputs that is an error123
if($val2=='error123'){
echo 'that is an error123<br />';
}else{
echo 'that is not an error123<br />';
}
Run Code Online (Sandbox Code Playgroud) 我试图找到一个匹配任何字符串与两个连续反斜杠的正则表达式.我正在尝试各种变化,任何帮助?和处理反斜杠的信息
b='\\mystring'
if b=~/\\\\/
puts "it matches"
end
Run Code Online (Sandbox Code Playgroud)
我似乎无法得到这个匹配.
javascript ×2
php ×2
bundler ×1
ios ×1
jquery ×1
json ×1
objective-c ×1
regex ×1
ruby ×1
swift ×1
uitableview ×1
vuex ×1